-
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 17 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,27 @@ | ||
'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() { | ||
Auth.resetPassword($scope.email).then(function () { | ||
$scope.passwordResetSent = true; | ||
}, | ||
function(response) { | ||
// Too many requests. | ||
if (response.status == 429) { | ||
$scope.ErrorMsg = 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) { | ||
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 injection of |
||
|
||
// 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 (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,35 @@ | ||
'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, localStorageService, accessToken) { | ||
|
||
// If 'access-token' is not provided as a URL parameter, 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'); | ||
} | ||
|
||
$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) { | ||
localStorageService.set('access_token', 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.
|
||
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,44 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc function | ||
* @name clientApp.controller:SignUpCtrl | ||
* @description | ||
* # SignUpCtrl | ||
* Controller of the clientApp | ||
*/ | ||
angular.module('clientApp') | ||
.controller('SignUpCtrl', function ($scope, Auth) { | ||
|
||
/** | ||
* Send a password reset link. | ||
*/ | ||
$scope.signUp = function(user) { | ||
|
||
// Reset the flags before each request. | ||
$scope.emailNotAvailable = false; | ||
$scope.usernameNotAvailable = false; | ||
|
||
Auth.usernameAvailable(user.username).then(function(response) { | ||
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.
read http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html |
||
if (response.data.data.available) { | ||
Auth.emailAvailable(user.email).then(function(response) { | ||
if (response.data.data.available) { | ||
// Email is available. | ||
Auth.signUp(user).then(function() { | ||
// User registered successfully. | ||
$scope.signedUp = true; | ||
}); | ||
} | ||
else { | ||
// Email is not available. | ||
$scope.emailNotAvailable = true; | ||
} | ||
}); | ||
} | ||
else { | ||
// Username is not available. | ||
$scope.usernameNotAvailable = true; | ||
} | ||
}); | ||
}; | ||
}); |
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, $log, localStorageService) { | ||
|
||
// A private cache key. | ||
var cache = {}; | ||
|
@@ -43,6 +43,26 @@ angular.module('clientApp') | |
return deferred.promise; | ||
} | ||
|
||
/** | ||
* Verify a user. | ||
* | ||
* @param token | ||
* @returns {*} | ||
*/ | ||
this.verifyEmail = function(token) { | ||
localStorageService.set('access_token', token); | ||
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.
|
||
|
||
// 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> | ||
If the username is registered in our system we'll send you an email with instructions. | ||
</div> | ||
|
||
<div class="alert alert-danger fade in" ng-show="ErrorMsg"> | ||
<i class="fa fa-times-circle fa-fw fa-lg"></i> | ||
Request failed. | ||
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. improve, there's request fail, and there's |
||
</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" 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 || ErrorMsg" 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.
camelCase (
signup
,verifyEmail
)