public AuthTokenModel Registration(ReistrationModel reg) { try { RegistrationModelChecker.Check(reg); if (GetUser(reg.Email) != null) { return(new AuthTokenModel(0, string.Empty, "Username alredy used!", string.Empty)); } _identityRepository.Registration(reg.Email, reg.Password); GrooveAppContext.Id = Convert.ToInt64(_httpContextAccessor.HttpContext.User.Identity.Name); return(Autorize(reg.Email, reg.Password)); } catch (Exception e) { return(new AuthTokenModel(0, string.Empty, e.Message, string.Empty)); } }
public static void Check(ReistrationModel reg) { if (reg.Password != reg.ConfirmPassword) { throw new ArgumentException("Password and Confirm Password not equal"); } if (reg.Email != reg.ConfirmEmail) { throw new ArgumentException("Email and Confirm Email not equal"); } if (!(reg.Password.Length < 7)) { throw new ArgumentException("Please, insert more strong password"); } if (!reg.Email.Contains('@')) { throw new ArgumentException("Thats not email"); } }