示例#1
0
 public static void SetConnectionInfo(this HttpSessionStateBase session, ConnectionInfo connectionInfo)
 {
     session[ConnectionInfoSessionId] = connectionInfo;
 }
示例#2
0
        public ActionResult Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var connection = new FCDBDataContext())
                {
                    var userAccount = connection.Accounts
                        .Where(account => account.Email == model.Email && account.Status == (int)UserAccountStatus.Active).ToList()
                        .FirstOrDefault(account => PasswordHash.PasswordHash.ValidatePassword(model.Password, account.PasswordHash));
                    
                    if (userAccount != null)
                    {
                        var connectionInfo = new ConnectionInfo(Guid.NewGuid()) { AccountId = userAccount.Id };

                        this.Session.SetConnectionInfo(connectionInfo);
                        ActiveConnections.Add(connectionInfo.ConnectionId, connectionInfo);

                        userAccount.LastLoggedOn = DateTime.Now;
                        userAccount.LastLoginIp = this.Request.UserHostAddress;

                        connection.SubmitChanges();
                        
                        return this.RedirectToAction("Index");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid email or password.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }