public IUserService.UserEntitis Create(Account account, string password) { try { MailAddress m = new MailAddress(account.Email); } catch (FormatException) { throw new AppException("Email not formatted correctly"); } var acc = context.Accounts.SingleOrDefault(p => p.Email == account.Email); if (acc != null) { throw new AppException("Email already exist"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); account.PasswordHash = passwordHash; account.PasswordSalt = passwordSalt; account.Balance = 0; account.OnReady = false; context.Accounts.Add(account); context.SaveChanges(); account = context.Accounts .Include(p => p.Role).SingleOrDefault(p => p.Id == account.Id); IUserService.UserEntitis userEntitis = new IUserService.UserEntitis(account); userEntitis.createUserToken(); return(userEntitis); }
public IActionResult Register([FromBody] RegisterModel model) { Account account = new Account(); account.Name = model.Name; account.Phone = model.Phone; account.Email = model.Email; account.RoleId = model.RoleID; //string path = _webHostEnvironment.WebRootPath + "\\Avatars\\default.jpg"; account.AvatarUrl = "\\Avatars\\default.jpg"; try { IUserService.UserEntitis userEntitis = userService.Create(account, model.Password).createUserToken(); return(Ok(userEntitis)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public IUserService.UserEntitis Auth(string email, string password) { var list = context.Accounts .Include(p => p.FreelancerSkills).ThenInclude(p => p.Skill) .AsSplitQuery() .Include(p => p.FreelancerServices).ThenInclude(p => p.Service) .AsSplitQuery() .Include(p => p.Specialty) .AsSplitQuery() .Include(p => p.Role) .AsSplitQuery() .Include(p => p.RatingFreelancers) .AsSplitQuery() .Include(p => p.Level) .AsSplitQuery() .Include(p => p.OfferHistories) .AsSplitQuery() .Include(p => p.CapacityProfiles) .ThenInclude(p => p.ProfileServices).ThenInclude(p => p.Service) .AsSplitQuery().ToList(); Account account = list.SingleOrDefault(p => p.Email == email); if (account == null) { throw new AppException("Email doesn't exist"); } if (account.BannedAtDate != null) { throw new AppException("Your account was bannish"); } if (!VerifyPasswordHash(password, account.PasswordHash, account.PasswordSalt)) { throw new AppException("Password not correct"); } IUserService.UserEntitis userEntitis = new IUserService.UserEntitis(account); userEntitis.createUserToken(); return(userEntitis); }