예제 #1
0
        public async Task <IHttpActionResult> RegisterNewUser([FromBody] UserRegisterData user)
        {
            if (this.UserAlreadyExists(user.username))
            {
                return(BadRequest("User already exists!"));
            }

            if (!this.PasswordsMatch(user.password, user.confirm))
            {
                return(BadRequest("Passwords don't match"));
            }

            try
            {
                await this.userRepository.CreateUser(user);

                await this.subscribersEvents.SendEventToSubscriber(user);

                return(Ok("User created successfully"));
            }
            catch (System.Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #2
0
 public async Task CreateUser(UserRegisterData user)
 {
     using (var db = new TokeServiceDbEntities())
     {
         db.Users.Add(this.MapUser(user));
         await db.SaveChangesAsync();
     }
 }
예제 #3
0
 private User MapUser(UserRegisterData newUser)
 {
     return(new User()
     {
         role = (int)Shared.Identity_Provider.Role.Candidate,
         guid = newUser.guid,
         instance = (int)Shared.Identity_Provider.Instance.HeznekService,
         email = newUser.email,
         username = newUser.username,
         password = newUser.password.EncryptPassword()
     });
 }