Apologies for any lack of knowledge on this framework and its elements as I am in the process of learning through practice.
I have configured a simple application using angular-fullstack
and am currently exploring some tasks that I would like guidance on. Specifically, I am interested in adding an extra form field to the user registration process to restrict sign-ups to individuals who provide a predetermined security code shared verbally. If an invalid code is entered, the new user should not be created, and possibly a message can be displayed to notify the user.
In my
server/config/environment/index.js
file, I have introduced a new item under the secrets
key which will be used to validate the code provided.
...
// Secret for session, you will want to change this and make it an environment variable
secrets: {
session: 'myapp-secret',
secretCode: 'my-secret' // pre-determined secret code
},
...
In the form, I have added the additional field with ng-model="secret"
. The form directs to the controller's register
function, so I need to include the value of the new input when passing it to Auth.createUser
:
$scope.register = function(form){
...
if (form.$valid) {
Auth.createUser({
name: $scope.user.name,
email: $scope.user.email,
password: $scope.user.password,
secret: $scope.secret // Field to pass to the user controller
})
}
...
}
Next, I need to implement the logic for checking the secret code within the create
function of
server/api/user/user.controller.js
.
/**
* Creates a new user
*/
exports.create = function(req, res, next) {
...
if (req.body.secret !== config.secrets.secretCode) {
// Cancel new user creation
};
...
};
My current query pertains to how I should handle this scenario within the if
statement. Upon investigating the framework, it appears that perhaps I could simply redirect or return to the /signup
page with an error message. However, I am uncertain about the most appropriate approach in this situation.
I have explored various angles on this matter but have yet to experience the "Eureka!" moment where I feel assured that I am approaching it correctly. Is my method unconventional?