public async Task SignUp(UserCredintails creds) { try { await UserRepo.Add(creds); } catch (Exception ex) { if (DUPLICATE_LOGIN_EXCEPTION.IsMatch(ex.Message)) { throw new UserConflictException(); } } }
public async Task <UserSession> LogIn(UserCredintails creds) { UserSession user = await UserRepo.LogIn(creds); if (user == null) { throw new LogInFailedException(); } return(user); }
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); }