private void LoginLogWrite(BCEnterpriseContext db, UserLoginState userLoginState, EnterpriseData.Common.LoginStatus status, string description) { if (userLoginState == null) { return; } var loginLog = new UserLoginLog { UserID = userLoginState.UserID, UserName = userLoginState.UserName, Device = userLoginState.Device, IP = userLoginState.LoginIP, Status = (int)status, Description = description }; if (status == EnterpriseData.Common.LoginStatus.Login && userLoginState.LoginTime.HasValue) { loginLog.Time = userLoginState.LoginTime.Value; } else { loginLog.Time = ML.BC.EnterpriseData.Model.Extend.DBTimeHelper.DBNowTime(db); } LoginLogWrite(db, loginLog); }
private bool ValidateUserToken(ResponseModel response, byte[] userToken, out string userName) { userName = null; var user = BinarySerialization.ReadFromBytes <TokenRequestModel>(userToken); var userlist = UserLoginState.FindAllByToken(user.Token); if (userlist.Count == 0) { response.Status = -2; response.Message = "用户未登录"; return(false); } if (userlist[0].ExpireDate < DateTime.Now) { response.Status = -3; response.Message = "用户登录已过期,请重新登录"; userlist[0].Delete(); return(false); } userName = userlist[0].UserName; if (userlist.Count > 1) { userlist.RemoveAt(0); userlist.Delete(); } return(true); }
private UserLoginState AddUserInfo(string userName) { var userlist = UserLoginState.FindAllByUserName(userName); if (userlist.Count > 0) { DateTime expiredDate = DateTime.Now; var expiredUser = from UserLoginState u in userlist where u.ExpireDate < expiredDate select u; if (expiredUser.Count() > 0) { EntityList <UserLoginState> tempList = new EntityList <UserLoginState>(expiredUser); int count = tempList.Delete(); } } UserLoginState userInfo = new UserLoginState(); userInfo.Token = Guid.NewGuid().ToString("d"); userInfo.UserName = userName; userInfo.LoginDate = DateTime.Now; userInfo.ExpireDate = userInfo.LoginDate.AddHours(ConfigurationHelper.SessionTimeout); userInfo.CreateBy = userInfo.UserName; userInfo.CreateDT = userInfo.LoginDate; userInfo.ProductCode = productCode; int r = userInfo.Insert(); if (r != 1) { throw new Exception("用户登录信息写入失败"); } return(userInfo); }
public bool UpdateClientLogin(UserLoginState state) { const string sql = @" IF ( EXISTS ( SELECT UserId FROM UserLoginState WHERE UserId = @UserId ) ) BEGIN UPDATE UserLoginState SET ClientLastLoginIpAddress = @ClientLastLoginIpAddress , ClientLogin = 1 , ClientLastLoginTime = @ClientLastLoginTime WHERE UserId = @UserId END ELSE BEGIN INSERT INTO UserLoginState ( UserId , ClientLastLoginIpAddress , ClientLogin , ClientLastLoginTime ) VALUES ( @UserId , @ClientLastLoginIpAddress , 1 , @ClientLastLoginTime ) END"; using (var con = DbFactory.CreateConnection()) { return(con.Execute(sql, state) > 0); } }
public IUserLoginState Get(UserLoginId id) { IUserLoginState state = CurrentSession.Get <UserLoginState>(id); if (state == null) { state = new UserLoginState(); (state as UserLoginState).UserLoginId = id; } return(state); }
public IUserLoginState Get(UserLoginId id, bool nullAllowed) { IUserLoginState state = CurrentSession.Get <UserLoginState>(id); if (!nullAllowed && state == null) { state = new UserLoginState(); (state as UserLoginState).UserLoginId = id; } if (ReadOnlyProxyGenerator != null && state != null) { return(ReadOnlyProxyGenerator.CreateProxy <IUserLoginState>(state, new Type[] { }, _readOnlyPropertyNames)); } return(state); }
public byte[] Logout(byte[] userToken) { return(RunAction <ResponseModel>(() => { var user = BinarySerialization.ReadFromBytes <TokenRequestModel>(userToken); var userlist = UserLoginState.FindAllByToken(user.Token); if (userlist.Count > 0) { int r = userlist.Delete(); if (r != userlist.Count) { throw new Exception("删除用户登录状态记录失败"); } } })); }
private void Button_Click(object sender, RoutedEventArgs e) { UserLoginState.LogIn(_applicationUserRepository.LogIn(txt_UserName.Text, txt_Password.Password)); if (UserLoginState.LoggedInState) { if (UserLoginState.loggedUser.role.RoleName.ToLower() == "administrator") { var adminPanel = new AdminPanel(); adminPanel.Show(); Close(); } else { var userPanel = new UserPanel(); userPanel.Show(); Close(); } } else { MessageBox.Show("Nie odnaleziono użytkownika, lub podane hasło jest nieprawidłowe", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error); } }
public bool UpdateClientLogin(UserLoginState state) { return(_userDal.UpdateClientLogin(state)); }