Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool LoginUser(LoginUserBindingModel model, HttpSession session)
- {
- string username = null;
- string email = null;
- if (model.UsernameOrEmail.Contains(WebUtility.UrlDecode("@")))
- {
- email = model.UsernameOrEmail;
- }
- else
- {
- username = model.UsernameOrEmail;
- }
- User user = new User()
- {
- Password = model.Password,
- Username = username ?? string.Empty,
- Email = email ?? string.Empty
- };
- User userFromDb =
- this.Context.Users.FirstOrDefault(
- (u =>
- u.Password == user.Password &&
- (u.Username == model.UsernameOrEmail || u.Email == model.UsernameOrEmail)));
- if (userFromDb != null)
- {
- Login login = new Login()
- {
- IsActive = true,
- SessionId = session.Id,
- User = userFromDb
- };
- this.Context.Logins.Add(login);
- this.Context.SaveChanges();
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement