Created
May 20, 2016 01:16
-
-
Save travist/5988512c5d89461b27de7ca32d7af76c to your computer and use it in GitHub Desktop.
Auto Login/Register from Form Submission with Form.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bind to the submission of the form. | |
$rootScope.$on('formSubmission', function (event, submission) { | |
if (!submission) { | |
return; | |
} | |
// See if this is a new user or existing. | |
$http.get(AppConfig.appUrl + '/user/exists', { | |
params: { | |
'data.email': submission.data.email | |
} | |
}).then(function (result) { | |
// The user exists, send them a login | |
(new Formio(AppConfig.appUrl + '/user/login')).saveSubmission({ | |
data: { | |
email: submission.data.email, | |
password: submission.data.password | |
} | |
}).then(function(user) { | |
$state.go('home'); | |
}); | |
}, function (err) { | |
if (err.status === 404) { | |
// The user does not exist, register the user. | |
(new Formio(AppConfig.appUrl + '/user/register')).saveSubmission({ | |
data: { | |
firstName: submission.data.firstName, | |
lastName: submission.data.lastName, | |
email: submission.data.email, | |
phoneNumber: submission.data.phoneNumber, | |
password: submission.data.password | |
} | |
}).then(function(user) { | |
$state.go('home'); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment