public CustomerViewModel Login(LoginViewModel loginViewModel) { var customer = _customerService.GetCustomerByEmail(loginViewModel.Email); var customerViewModel = new CustomerViewModel { Id = customer.Id, CustomerGuid = customer.CustomerGuid, Name = customer.Name, Email = customer.Email, PhoneNumber = customer.PhoneNumber, AmbassadorId = customer.AmbassadorId }; string providedPasswordHash = CustomerAuthenticationExtensions.HashPassword(loginViewModel.Password, customer.Salt); var passwordValid = (providedPasswordHash == customer.Password); if (passwordValid) { customerViewModel.Token = _jsonWebTokenService.GenerateJSONWebToken(customer); customerViewModel.PasswordValid = true; } else { customerViewModel.PasswordValid = false; } return(customerViewModel); }
public CustomerViewModel RegisterSupporter(RegisterSupporterViewModel registerSupporterViewModel) { var customer = _customerService.GetCustomerByEmail(registerSupporterViewModel.Email); if (customer == null) { var salt = CustomerAuthenticationExtensions.GenerateSalt(); customer = new Customer { Name = registerSupporterViewModel.Name, Email = registerSupporterViewModel.Email, PhoneNumber = registerSupporterViewModel.PhoneNumber, Salt = salt, Password = CustomerAuthenticationExtensions.HashPassword(registerSupporterViewModel.Password, salt), Active = true, AmbassadorId = registerSupporterViewModel.AmbassadorId, CreatedOn = DateTime.UtcNow }; _customerService.InsertCustomer(customer); } return(new CustomerViewModel { Id = customer.Id, CustomerGuid = customer.CustomerGuid, Name = customer.Name, Email = customer.Email, PhoneNumber = customer.PhoneNumber, AmbassadorId = customer.AmbassadorId, Token = _jsonWebTokenService.GenerateJSONWebToken(customer) }); }