示例#1
0
        public async Task <ActionResult <UserModel> > Register(SignupDtoModel signupModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await(_repository as UsersRepository).Register(signupModel);

            return(CreatedAtAction("Register", user));
        }
示例#2
0
        public async Task <UserDtoModel> Register(SignupDtoModel signupModel)
        {
            var newUser = new UserModel
            {
                Email        = signupModel.Email.Trim(),
                Name         = signupModel.Name.Trim(),
                PasswordHash = PasswordHasher.HashPassword(signupModel.Password)
            };

            _entitySet.Add(newUser);
            await SaveChangesAsync();

            newUser.PasswordHash = null;
            newUser.AuthToken    = GenerateAuthToken(signupModel.Email);
            return(_mapper.Map <UserDtoModel>(newUser));
        }