示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
 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));
 }
示例#10
0
 public void UpdateCustomerWebAccount(CustomerWebAccount customerWebAccount)
 {
     customerWebAccount.Updated = DateTime.Now;
     _dbContext.WebAccounts.Update(customerWebAccount);
     _dbContext.SaveChanges();
 }