Skip to content

Instantly share code, notes, and snippets.

@travist
Created January 30, 2017 14:08
Show Gist options
  • Select an option

  • Save travist/23f16a361da87b35b796d9a379321ef9 to your computer and use it in GitHub Desktop.

Select an option

Save travist/23f16a361da87b35b796d9a379321ef9 to your computer and use it in GitHub Desktop.
Reset Password Workflow with Form.io
<h3>Please provide your new password to reset your password.</h3>
<formio form="form"></formio>
(function() {
'use strict';
angular
.module('myApp')
.config(routerConfig);
/** @ngInject */
function routerConfig(
$stateProvider,
$urlRouterProvider,
FormioResourceProvider,
FormioFormBuilderProvider,
AppConfig,
$injector
) {
$stateProvider
.state('auth/reset', {
url: '/reset',
templateUrl: 'sendreset.html',
controller: ['$scope', function($scope) {
$scope.resetSent = false;
$scope.$on('formSubmission', function() {
$scope.resetSent = true;
});
}]
})
.state('changepass', {
url: '/changepass',
templateUrl: 'changepass.html',
controller: ['$scope', '$state', '$rootScope', 'Formio', 'AppConfig', function($scope, $state, $rootScope, Formio, AppConfig) {
$scope.form = null;
(new Formio(AppConfig.forms.changePasswordForm)).loadform().then(function(form) {
$scope.form = form;
});
$scope.$on('formSubmission', function(event, submission) {
$rootScope.user.data.password = submission.data.password;
var submissionUrl = AppConfig.resources.user.form + '/submission/' + $rootScope.user._id;
(new Formio(submissionUrl)).saveSubmission($rootScope.user).then(function() {
$state.go('home');
});
});
}]
});
}
})();
<h3>Please click on the following link to reset your password.</h3>
<br/>
<a href="http://myapp.com?token=[[token(data.email=user)]]#changepass" class="btn-primary">Change Password</a>
<formio src="sendResetForm" ng-if="!resetSent"></formio>
<div class="well" ng-if="resetSent">
<p>We have sent you an email to reset your password.</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment