Example #1
0
 public async Task SignUp(UserCredintails creds)
 {
     try { await UserRepo.Add(creds); }
     catch (Exception ex)
     {
         if (DUPLICATE_LOGIN_EXCEPTION.IsMatch(ex.Message))
         {
             throw new UserConflictException();
         }
     }
 }
Example #2
0
        public async Task <UserSession> LogIn(UserCredintails creds)
        {
            UserSession user = await UserRepo.LogIn(creds);

            if (user == null)
            {
                throw new LogInFailedException();
            }

            return(user);
        }
Example #3
0
        public async Task <UserSession> SignUp([FromBody] UserSignUpFormDto signUpForm)
        {
            if (!ModelState.IsValid)
            {
                throw new InvalidDataException();
            }

            signUpValidator.Validate(signUpForm);

            UserCredintails signUpCredintails = new UserCredintails(signUpForm.login, Encryptor.Encrypt(signUpForm.password));
            await userService.SignUp(signUpCredintails);

            UserCredintails logInCredintails = new UserCredintails(signUpCredintails.login, Encryptor.Encrypt(signUpCredintails.passwordEncoded));
            UserSession     session          = await userService.LogIn(logInCredintails);

            WebApiApplication.DI.Resolve <SessionTable>().LogIn(session);
            return(session);
        }