public void SendMail(CustomerWebAccount customerWebAccount, EmailValidation emailValidation) { MailMessage mailMessage = new MailMessage("*****@*****.**", customerWebAccount.Email); mailMessage.Body = "blah blub: http://www.valkyra.de/api/CustomerRegister/validate/" + emailValidation.ValidationId; mailMessage.Subject = "Valkyra Shop Email validation Link"; smptClient.Send(mailMessage); }
public EmailValidation CreateValidationLink(CustomerWebAccount customerWebAccount) { EmailValidation _emailValidation = new EmailValidation(); _emailValidation.Created = DateTime.Now; _emailValidation.CustomerWebAccount = customerWebAccount; _emailValidation.ExpiredDate = DateTime.Now.AddDays(7); _emailValidation.ValidationId = Guid.NewGuid(); _dbContext.EmailValidations.Add(_emailValidation); _dbContext.SaveChanges(); return(_emailValidation); }
public CustomerWebToken CreateToken(CustomerWebAccount customerWebAccount) { CustomerWebToken customerWebToken = new CustomerWebToken() { Created = DateTime.Now, Expire = DateTime.Now, Updated = DateTime.Now, CustomerWebAccount = customerWebAccount }; string _tempToken = new Guid().ToString() + ";" + customerWebAccount.Id; customerWebToken.Token = Convert.ToBase64String(Encoding.UTF8.GetBytes(_tempToken)); _dbContext.CustomerWebTokens.Add(customerWebToken); _dbContext.SaveChanges(); return(customerWebToken); }
public ValidationResult Register(CustomerWebAccount customerWebAccount) { CustomerWebAccount _customerWebAccount = customerWebAccount; ValidationResult _validationResult = _valkyraRegisterRepository.EmailExists(customerWebAccount); if (_validationResult.ResultCode == 0) { _valkyraRegisterRepository.CreateCustomerWebAccount(_customerWebAccount); EmailValidation emailValidation = _valkyraRegisterRepository.CreateValidationLink(_customerWebAccount); SendMailHelper sendMailHelper = new SendMailHelper(); sendMailHelper.SendMail(customerWebAccount, emailValidation); } return(_validationResult); }
public ValidationResult EmailExists(CustomerWebAccount customerWebAccount) { ValidationResult _validationResult = new ValidationResult(); CustomerWebAccount _customerWebAccount = _dbContext.WebAccounts.FirstOrDefault(x => x.Email == customerWebAccount.Email); if (_customerWebAccount == null) { _validationResult.ResultCode = 0; _validationResult.ResultMessage = "Email Validation Erfolgreich"; } else { _validationResult.ResultCode = 1; _validationResult.ResultMessage = "Email schon in Benutzung"; } return(_validationResult); }
public bool CreateCustomerWebAccount(CustomerWebAccount customerWebAccount) { int result = 0; Customer customer = new Customer { Email = customerWebAccount.Email, Created = DateTime.Now }; _dbContext.Add(customer); result += _dbContext.SaveChanges(); customerWebAccount.Created = DateTime.Now; customerWebAccount.Password = StringToHash(customerWebAccount.Password); customerWebAccount.Customer = customer; _dbContext.WebAccounts.Add(customerWebAccount); result += _dbContext.SaveChanges(); return(result != 0 ? false : true); }
public CustomerRegisterLoginViewModel Login(WebLogin webLogin) { CustomerWebAccount customerWebAccount = _valkyraRegisterRepository.GetAccountForLogin(webLogin); CustomerRegisterLoginViewModel customerRegisterLoginViewModel = new CustomerRegisterLoginViewModel(); customerRegisterLoginViewModel.FunctionName = "LoginResult"; if (customerWebAccount == null) { customerRegisterLoginViewModel.ValidationResultMessage = "Username or password wrong!"; } else { CustomerWebToken customerWebToken = _valkyraRegisterRepository.CreateToken(customerWebAccount); customerRegisterLoginViewModel.Token = customerWebToken.Token; customerRegisterLoginViewModel.Expire = customerWebToken.Expire; customerRegisterLoginViewModel.CustomerId = customerWebAccount.Customer.Id; } return(customerRegisterLoginViewModel); }
public void Validate(string id) { if (!string.IsNullOrWhiteSpace(id) && id != "undefined") { EmailValidation emailValidation = _valkyraRegisterRepository.ValidationExist(id); if (emailValidation != null) { CustomerWebAccount customerWebAccount = _valkyraRegisterRepository.GetCustomerWebAccount(emailValidation.CustomerWebAccountId); customerWebAccount.Verified = true; _valkyraRegisterRepository.UpdateCustomerWebAccount(customerWebAccount); } else { throw new Exception(); } } else { throw new Exception(); } }
public ValidationResult Post([FromBody] CustomerWebAccount customerWebAccount) { return(_registrationService.Register(customerWebAccount)); }
public void UpdateCustomerWebAccount(CustomerWebAccount customerWebAccount) { customerWebAccount.Updated = DateTime.Now; _dbContext.WebAccounts.Update(customerWebAccount); _dbContext.SaveChanges(); }