-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Registration & Reset password #68
base: master
Are you sure you want to change the base?
Changes from 33 commits
52a306a
bce2ec0
d8be92d
feb0c2d
7236eb4
309cb12
8da77cf
70595ce
2f3c7eb
70b62d9
701a538
ed95f95
c081b8c
40ce87c
48f8f68
285b6e9
3673dcc
a03bfa0
70b5b56
cb081e4
6a38f14
a5d061c
3a094b9
7174bd6
bf0b5f8
fe3cf58
9337802
942507a
e811c6d
d52578c
245e436
21dc4a7
90a7201
1afa24f
b51a293
b3af456
a5883a1
ae513bc
159671d
237c8a7
2377d6f
b2804c1
32ea7af
d4969d7
d9c2023
5292ce9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc function | ||
* @name clientApp.controller:ForgotPasswordCtrl | ||
* @description | ||
* # ForgotPasswordCtrl | ||
* Controller of the clientApp | ||
*/ | ||
angular.module('clientApp') | ||
.controller('ForgotPasswordCtrl', function ($scope, Auth) { | ||
|
||
/** | ||
* Send a password reset link. | ||
*/ | ||
$scope.forgotPassword = function() { | ||
// Reset the error message for each request. | ||
$scope.ErrorMsg = false; | ||
|
||
Auth.resetPassword($scope.email).then(function () { | ||
$scope.passwordResetSent = true; | ||
}, | ||
function(response) { | ||
$scope.ErrorMsg = response.data.title; | ||
|
||
// Too many requests. | ||
if (response.status == 429) { | ||
$scope.ErrorMsg = response.statusText; | ||
$scope.TooManyRequests = true; | ||
} | ||
}); | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,14 @@ | |
* Controller of the clientApp | ||
*/ | ||
angular.module('clientApp') | ||
.controller('LoginCtrl', function ($scope, Auth, $state) { | ||
.controller('LoginCtrl', function ($scope, Auth, $state, Account, accessToken) { | ||
|
||
// Try to verify the email when access token is being passed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
// Try to verify the email when access token is being passed.
if ($state.current.name == 'verifyEmail' && accessToken) {
Account.verifyEmail(accessToken).then(function () {
$scope.emailVerified = true;
});
} |
||
if ($state.current.name == 'verifyEmail' && accessToken) { | ||
Account.verifyEmail(accessToken).then(function () { | ||
$scope.emailVerified = true; | ||
}); | ||
} | ||
|
||
// Will be FALSE during login GET period - will cause the login button to be | ||
// disabled. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc function | ||
* @name clientApp.controller:ResetPasswordCtrl | ||
* @description | ||
* # ResetPasswordCtrl | ||
* Controller of the clientApp | ||
*/ | ||
angular.module('clientApp') | ||
.controller('ResetPasswordCtrl', function ($scope, Auth, $state, $location, Account, accessToken) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this injection of |
||
|
||
// If 'access-token' is not provided redirect to login. | ||
if (!accessToken) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ordavidil Please move |
||
$state.go('login'); | ||
} | ||
|
||
// Determine if password was reset successfully. | ||
$scope.passwordSaved = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/** | ||
* Setting the access token in the localStorage so we can get the account | ||
* information and pull out the user ID from it to PATCH the user entity. | ||
* | ||
* @param password | ||
* The new password. | ||
*/ | ||
$scope.saveNewPassword = function(password) { | ||
Auth.setAccessToken(accessToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ordavidil Please remove |
||
|
||
Account.get().then(function(user) { | ||
Auth.savePassword(user.id, password).then(function() { | ||
$scope.passwordSaved = true; | ||
}); | ||
}); | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc function | ||
* @name clientApp.controller:SignUpCtrl | ||
* @description | ||
* # SignUpCtrl | ||
* Controller of the clientApp | ||
*/ | ||
angular.module('clientApp') | ||
.controller('SignUpCtrl', function ($scope, Auth) { | ||
|
||
// Reset the flags. | ||
$scope.emailAvailable = true; | ||
$scope.usernameAvailable = true; | ||
|
||
/** | ||
* Send a password reset link. | ||
*/ | ||
$scope.signUp = function(user) { | ||
// Clear the error before each request. | ||
$scope.signupError = undefined; | ||
|
||
Auth.usersAvailability(user).then(function(response) { | ||
$scope.usernameAvailable = response.data.data.available.name; | ||
$scope.emailAvailable = response.data.data.available.mail; | ||
|
||
if ($scope.emailAvailable && $scope.usernameAvailable) { | ||
Auth.signUp(user).then(function() { | ||
// User registered successfully. | ||
$scope.signedUp = true; | ||
}, function (response) { | ||
// Error trying to register the user. | ||
$scope.signupError = response.data.detail; | ||
}); | ||
} | ||
}); | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* Service in the clientApp. | ||
*/ | ||
angular.module('clientApp') | ||
.service('Account', function ($q, $http, $timeout, Config, $rootScope, $log) { | ||
.service('Account', function ($q, $http, $timeout, Config, $rootScope, Auth) { | ||
|
||
// A private cache key. | ||
var cache = {}; | ||
|
@@ -43,6 +43,26 @@ angular.module('clientApp') | |
return deferred.promise; | ||
} | ||
|
||
/** | ||
* Verify a user. | ||
* | ||
* @param accessToken | ||
* @returns {*} | ||
*/ | ||
this.verifyEmail = function(accessToken) { | ||
Auth.setAccessToken(accessToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ordavidil Please remove this param |
||
|
||
// After setting the access token in the local storage, try to get the | ||
// user account from the data, if succeed then change its status. | ||
return getDataFromBackend().then(function(user) { | ||
return $http({ | ||
method: 'PATCH', | ||
url: Config.backend + '/api/users-update/' + user.id, | ||
data: {status: 1} | ||
}); | ||
}); | ||
}; | ||
|
||
/** | ||
* Save meters in cache, and broadcast en event to inform that the meters data changed. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ | |
min-height: 500px; | ||
} | ||
|
||
.vertical-space { | ||
margin-top: 15px; | ||
margin-bottom: 15px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<div id="dashboard-forgot-password"> | ||
<div class="page-forgot-password"> | ||
<div class="forgot-password-header"> | ||
<section class="logo text-center"> | ||
<h1>Skeleton</h1> | ||
</section> | ||
</div> | ||
|
||
<div class="forgot-password-body"> | ||
<div class="container"> | ||
|
||
<div class="alert alert-success fade in" ng-show="passwordResetSent"> | ||
<i class="fa fa-check-circle fa-fw fa-lg"></i> | ||
An email with instructions has been sent to "{{ email }}". | ||
</div> | ||
|
||
<div class="alert alert-danger fade in" ng-show="ErrorMsg"> | ||
<i class="fa fa-times-circle fa-fw fa-lg"></i> | ||
{{ ErrorMsg }} | ||
</div> | ||
|
||
<h4>Forgot your password?</h4> | ||
<p>Enter your email to recover your password.</p> | ||
|
||
<div class="form-container"> | ||
<form class="form-horizontal" id="login" ng-submit="forgotPassword()"> | ||
<fieldset> | ||
<div class="form-group"> | ||
<div class="input-group input-group-first"> | ||
<span class="input-group-addon"> | ||
<span class="ti-email"></span> | ||
</span> | ||
<input ng-disabled="passwordResetSent || TooManyRequests" ng-model="email" name="email" type="text" class="form-control input-lg" placeholder="Email" required> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input ng-disabled="passwordResetSent || TooManyRequests" type="submit" class="btn btn-primary btn-lg btn-block text-center" id="submit" value="Recover Password" /> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<a ui-sref="login">Back to login</a> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ordavidil Please remove this injection of
accessToken
(Not needed) and replace it with theemailVerified
.