public void CheckCanLogOut() { LoggedInUser user = new LoggedInUser("Test", null, 1); AuthenticationHelper.AddSessionToContext(Context, user); Assert.AreEqual(Context.CurrentUser, user); m_loginController.Logout(); Assert.AreEqual(Context.CurrentUser, null); }
public void Save([DataBind("User")]User user) { User existingUser = ActiveRecordBase<User>.FindOne(Restrictions.Like("Email", user.Email, MatchMode.Exact).IgnoreCase()); if (null == existingUser) { user.SaveAndFlush(); var userToLog = new LoggedInUser(user.Name, null, user.Id); AuthenticationHelper.AddSessionToContext(Context, userToLog); Redirect("Home", "Index"); } else { Flash["User"] = user; Flash["error"] = "OMG! This email has already been used!!."; RedirectToAction("Register"); } }
public void Login(string username, string password) { //obviosuly this is not production code. User user = ActiveRecordBase<User>.FindOne(Restrictions.And( Restrictions.Eq("Username", username), Restrictions.Eq("Password", password)) ); if (null != user) { var loggedInUser = new LoggedInUser(user.Name, null, user.Id); AuthenticationHelper.AddSessionToContext(Context , loggedInUser); Redirect("Home","Index"); } else { Flash["error"] = string.Format("Are you sure {0} is your username and {1} is your password", username, password); RedirectToAction("Index"); } }