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 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); }