Exemplo n.º 1
0
        public LoginResultViewModel Login(LoginViewModel loginViewModel)
        {
            var result = new LoginResultViewModel();
            var entity = _usersRepository.Login(loginViewModel.Identifier, loginViewModel.Credential.ToMd5());

            result.Identifier = loginViewModel.Identifier;
            result.User       = _mapper.Map <UsersViewModel>(entity);
            if (entity == null)
            {
                result.LoginSuccess = false;
                result.Message      = "Account or password wrong ";
                result.Result       = LoginResult.AccountOrPasswordWrong;
            }
            else
            {
                result.LoginSuccess = true;
            }
            var loginLog = new LoginLogs
            {
                UserId    = entity?.Id,
                LoginName = entity.Name,
                IP        = loginViewModel.IP,
                LoginTime = DateTime.Now,
                Message   = result.Message
            };

            //增加日志
            return(result);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string str = string.Empty;

            try
            {
                LoginLogs               objLoginLogs           = new LoginLogs();
                LoginLogsRepository     objLoginLogsRepository = new LoginLogsRepository();
                List <LoginLogsTracker> lstLoginLogsTracker    = objLoginLogsRepository.GetAllLoginLogsDetails();
                foreach (LoginLogsTracker item in lstLoginLogsTracker)
                {
                    try
                    {
                        str += "<tr class=\"gradeX\"><td><a href=\"UserLoginDetails.aspx?id=" + item._UserId + "\">" + item._UserName + "</a></td><td>" + item._count + "</td></tr>";
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Response.Write(str);
        }
Exemplo n.º 3
0
        public List <LoginLogs> GetLoginLog()
        {
            string           procName = "GetLoginLogs";
            SqlDataReader    reader   = SQLHelper.GetDataReader(procName, null);
            List <LoginLogs> list     = new List <LoginLogs>();

            while (reader.Read())
            {
                LoginLogs logs = new LoginLogs();
                logs.LogId = Convert.ToInt32(reader["LogId"]);
                if (string.IsNullOrEmpty(reader["ExitTime"].ToString()))
                {
                    logs.ExitTime = null;
                }
                else
                {
                    logs.ExitTime = Convert.ToDateTime(reader["ExitTime"]);
                }
                logs.LoginId    = Convert.ToInt32(reader["LoginId"]);
                logs.SPName     = reader["SPName"].ToString();
                logs.ServerName = reader["ServerName"].ToString();
                logs.LoginTime  = Convert.ToDateTime(reader["LoginTime"]);
                list.Add(logs);
            }
            reader.Close();
            return(list);
        }
Exemplo n.º 4
0
        public int LoginLogsAdd(LoginLogs info)



        {
            string LogiAdd = $"insert into LoginLogs values('{info.IP}','{DateTime.Now}','{info.UserAgent}')";

            return(sqlHelper.ExecuteNonQuery(LogiAdd));
        }
        public int WriteLoginLog(LoginLogs objLoginLog)
        {
            string sql = "insert into LoginLogs(LoginId, LoginName, ServerName, LoginTime) values(@LoginId,@LoginName,@LoginName,getdate());select @@identity;";

            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@LoginId", objLoginLog.LoginId),
                new SqlParameter("@LoginName", objLoginLog.LoginName),
                new SqlParameter("@ServerName", Dns.GetHostName())
            };
            return(Convert.ToInt32(Helper.SQLHelper.GetSingleResult(sql, param)));
        }
Exemplo n.º 6
0
        public int WriteLoginLog(LoginLogs objLogin)
        {
            string sql = "insert into LoginLogs(LoginId,SPName,ServerName)values(@LoginId,@SPName,@ServerName);select @@identity";

            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@LoginId", objLogin.LoginId),
                new SqlParameter("@SPName", objLogin.SPName),
                new SqlParameter("@ServerName", objLogin.SPName),
            };

            return(Convert.ToInt32(SQLHelper.GetSingleResult(sql, param)));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 写入登录日志,返回日志ID
        /// </summary>
        /// <param name="loginLog"></param>
        /// <returns></returns>
        public int WriteLoginLog(LoginLogs loginLog)
        {
            string sql = "INSERT INTO LoginLogs (LoginId,SPName,ServerName) VALUES (@LoginId,@SPName,@ServerName);SELECT @@IDENTITY";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@LoginId", loginLog.LoginId),
                new SqlParameter("@SPName", loginLog.SPName),
                new SqlParameter("@ServerName", loginLog.ServerName)
            };
            return(Convert.ToInt32(SqlHelper.GetSingleResult(sql, param)));
        }
        /// <summary>
        /// 写入登录日志
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        private int WriteLoginLog(LoginLogs log)
        {
            string sql = "insert into LoginLogs (LoginId,LoginName,ServerName,LoginTime) values (@LoginId,@LoginName,@ServerName,@LoginTime);select @@identity;";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@LoginId", log.LoginId),
                new SqlParameter("@LoginName", log.LoginName),
                new SqlParameter("@ServerName", log.ServerName),
                new SqlParameter("@LoginTime", log.LoginTime)
            };
            return(Convert.ToInt32(Helper.SqlHelper.GetSingleResult(sql, param)));
        }
Exemplo n.º 9
0
 private void LoginUser(IUser userInfo)
 {
     ForumUtils.WriteUserCookie(userInfo.ID, TypeConverter.StrToInt(DNTRequest.GetString("expires"), -1), this.config.Passwordkey, DNTRequest.GetInt("templateid", 0), DNTRequest.GetInt("loginmode", -1));
     this.oluserinfo    = OnlineUsers.UpdateInfo(this.config.Passwordkey, this.config.Onlinetimeout, userInfo.ID, "");
     this.olid          = this.oluserinfo.Olid;
     this.username      = userInfo.Name;
     this.userid        = userInfo.ID;
     this.usergroupinfo = UserGroup.FindByID(userInfo.GroupID);
     this.useradminid   = this.usergroupinfo.RadminID;
     Utils.WriteCookie("bindconnect", "1");
     OnlineUsers.UpdateAction(this.olid, UserAction.Login.ActionID, 0);
     LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
     Users.UpdateUserCreditsAndVisit(userInfo.ID, DNTRequest.GetIP());
 }
Exemplo n.º 10
0
 /// <summary>
 /// 登录操作
 /// </summary>
 /// <param name="userInfo"></param>
 private void LoginUser(ShortUserInfo userInfo)
 {
     #region 无延迟更新在线信息和相关用户信息
     ForumUtils.WriteUserCookie(userInfo.Uid, TypeConverter.StrToInt(DNTRequest.GetString("expires"), -1),
                                config.Passwordkey, DNTRequest.GetInt("templateid", 0), DNTRequest.GetInt("loginmode", -1));
     oluserinfo    = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout, userInfo.Uid, "");
     olid          = oluserinfo.Olid;
     username      = userInfo.Username;
     userid        = userInfo.Uid;
     usergroupinfo = UserGroups.GetUserGroupInfo(userInfo.Groupid);
     useradminid   = usergroupinfo.Radminid;   // 根据用户组得到相关联的管理组id
     Utils.WriteCookie("bindconnect", "true"); //将当前登录用户是否绑定QQ互联的状态设置为true
     OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0);
     LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
     Users.UpdateUserCreditsAndVisit(userInfo.Uid, DNTRequest.GetIP());
     #endregion
 }
        /// <summary>
        /// 退出日志
        /// </summary>
        public void ExitLog(LoginLogs objLog)
        {
            string sql = "update LoginLogs set ExitTime=@ExitTime where LogId=@LogId";

            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@ExitTime", SQLHelper.GetDBTime()),
                new SqlParameter("@LogId", objLog.LogId)
            };
            try
            {
                SQLHelper.Update(sql, parameters);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="sp"></param>
        /// <returns></returns>
        public SalesPerson UserLogin(SalesPerson sp)
        {
            string sql = "select SalesPersonId,SalesPersonName from SalesPerson where SalesPersonId=@SalesPersonId and LoginPassword=@LoginPassword";

            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@SalesPersonId", sp.SalesPersonId),
                new SqlParameter("@LoginPassword", sp.LoginPassword)
            };
            SqlDataReader reader = null;

            try
            {
                reader = Helper.SqlHelper.GetReader(sql, param);
            }
            catch (Exception ex)
            {
                Helper.LogHelper.WriteLog(ex.Message);
                throw ex;
            }
            if (reader.Read())
            {
                SalesPerson objSP = new SalesPerson()
                {
                    SalesPersonName = reader["SalesPersonName"].ToString(),
                    SalesPersonId   = Convert.ToInt32(reader["SalesPersonId"])
                };

                // 添加登录日志
                LoginLogs log = new LoginLogs()
                {
                    LoginId    = objSP.SalesPersonId,
                    LoginName  = objSP.SalesPersonName,
                    LoginTime  = DateTime.Now,
                    ServerName = Dns.GetHostName()
                };
                objSP.LogId = WriteLoginLog(log);

                return(objSP);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 管理员登录
        /// </summary>
        /// <param name="admins"></param>
        /// <returns></returns>
        public SysAdmins AdminLogin(SysAdmins admins)
        {
            admins = adminService.AdminLogin(admins);

            if (admins != null && admins.AdminStatus == 1)
            {
                //登录成功日志记录
                LoginLogs logInfo = new LoginLogs
                {
                    LoginId    = admins.LoginId,
                    SPName     = admins.AdminName,
                    ServerName = Dns.GetHostName()
                };
                var logId = adminService.WriteToLoginLog(logInfo);
                admins.LogId = logId;//为退出做准备
            }

            return(admins);
        }
Exemplo n.º 14
0
        public async Task <LoginResponse> LoginAsync(LoginViewModel login, bool rememmeberMe, int expireDays = 20, HttpContext context = null)
        {
            return(await Task.Run(async() =>
            {
                LoginResponse response = new();

                Users user = await _user.GetUserByEmailAsync(login.Email);
                if (user != null)
                {
                    if (await CheckPasswordAsync(user, login.Password))
                    {
                        Tokens token = await CreateTokenAsync(user, expireDays);
                        if (await _tokenCrud.InsertAsync(token) && await _tokenCrud.SaveAsync())
                        {
                            LoginLogs log = await CreateLogAsync(token, context);
                            await _logCrud.InsertAsync(log); await _logCrud.SaveAsync();

                            //Create Success Type
                            if (rememmeberMe)
                            {
                                response.Success = new Success
                                {
                                    IsSucces = true,
                                    Key = token.TokenKey,
                                    Value = token.TokenValue
                                };
                            }

                            response.Status = LoginStatus.Success;
                            return response;
                        }
                        response.Status = LoginStatus.Exception;
                        return response;
                    }
                    response.Status = LoginStatus.WrongPassword;
                    return response;
                }

                response.Status = LoginStatus.UserNotFound;
                return response;
            }));
        }
Exemplo n.º 15
0
        /// <summary>
        /// 添加登录日志,返回日志编号
        /// </summary>
        /// <param name="logInfo"></param>
        /// <returns></returns>
        public int WriteLoginlog(LoginLogs logInfo)
        {
            string sql = "insert LoginLogs(LoginId, SPName, ServerName) values (@LoginId,@SPName,@ServerName);select @@identity";

            SqlParameter[] salParameters = new SqlParameter[]
            {
                new SqlParameter("@LoginId", logInfo.LoginId),
                new SqlParameter("@SPName", logInfo.SPName),
                new SqlParameter("@ServerName", logInfo.ServerName),
            };

            try
            {
                return(Convert.ToInt32(SQLHelper.ExecuteScalar(sql, salParameters)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 登录日志
        /// </summary>
        /// <param name="objLog"></param>
        public void LoginLog(LoginLogs objLog)
        {
            //loginTime通过数据库中getdate方法获取数据库默认时间
            string sql = "insert into LoginLogs ( LoginId, LoginName, ServerName) values(@LoginId, @LoginName, @ServerName);select @@identity";

            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@LoginId", objLog.LoginId),
                new SqlParameter("@LoginName", objLog.LoginName),
                new SqlParameter("@ServerName", objLog.ServerName)
                //new SqlParameter("@LoginTime",objLog.LoginTime)
            };
            try
            {
                objLog.LogId = Convert.ToInt32(SQLHelper.GetSingleResult(sql, parameters));//获取当前登录时插入的LogId
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 17
0
        public SysAdmins AdminLogin(SysAdmins admin)
        {
            SysAdmins sys = adminServer.AdminLogin(admin);

            if (sys != null && sys.AdminStatus == 1)
            {
                LoginLogs log = new LoginLogs()
                {
                    Loginid    = sys.LoginId,
                    SPName     = sys.AdminName,
                    ServerName = Dns.GetHostName()
                };
                //保存当前管理员登录日志的ID
                sys.LoginLogId = saleServer.WriteSalesLog(log);
            }
            else
            {
                sys = null;
            }
            return(sys);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 日志记录返回本次日志的ID号
        /// </summary>
        /// <param name="logs"></param>
        /// <returns></returns>
        public int WriteSalesLog(LoginLogs logs)
        {
            string procName = "WriteLog";

            SqlParameter[] sp =
            {
                new SqlParameter("@LoginId",    SqlDbType.Int),
                new SqlParameter("@SPName",     SqlDbType.NVarChar,50),
                new SqlParameter("@ServerName", SqlDbType.NVarChar, 50)
            };
            sp[0].Value = logs.LoginId;
            sp[1].Value = logs.SPName;
            sp[2].Value = logs.ServerName;
            object res = SQLHelper.ExecuteScalar(procName, sp);

            if (res == null)
            {
                return(-1);
            }
            return(int.Parse(res.ToString()));
        }
 /// <Add>
 /// Add logging details of user
 /// </Add>
 /// <param name="loginLogs">Set Values in a LoginLogs Class Property and Pass the Object of LoginLogs Class (SocioBoard.Domain.LoginLogs).</param>
 public void Add(LoginLogs loginLogs)
 {
     try
     {
         //Creates a database connection and opens up a session
         using (NHibernate.ISession session = SessionFactory.GetNewSession())
         {
             //After Session creation, start Transaction.
             using (NHibernate.ITransaction transaction = session.BeginTransaction())
             {
                 //Proceed action, to save details.
                 session.Save(loginLogs);
                 transaction.Commit();
             } //End Transaction
         }     //End Session
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         logger.Error(ex.StackTrace);
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// 管理员登录逻辑
        /// </summary>
        /// <param name="sys"></param>
        /// <returns></returns>
        public SysAdmins AdminLogin(SysAdmins admin)
        {
            SysAdmins sys = manager.AdminLogin(admin);

            //管理员不是空,状态时启用状态
            if (sys != null && sys.AdminStatus == 1)
            {
                //可以登录,写入日志
                LoginLogs login = new LoginLogs()
                {
                    LoginId    = sys.LoginId,
                    SPName     = sys.AdminName,
                    ServerName = Dns.GetHostName()
                };
                //记录日志
                sys.LoginLogId = server.WriteSalesLog(login);
            }
            else
            {
                sys = null;
            }
            return(sys);
        }
Exemplo n.º 21
0
        public SysAdmins AdminLogin(SysAdmins admins)
        {
            //根据用户账号和密码调用查询用户登录
            SysAdmins sys = adminServer.AdminLogin(admins);

            //判断管理员账号状态
            if (sys != null && sys.AdminStatus == 1)
            {
                //写入日志
                LoginLogs log = new LoginLogs()
                {
                    LoginId    = sys.LoginId,
                    SPName     = sys.AdminName,
                    ServerName = Dns.GetHostName()
                };
                //保存当前管理员登录ID
                sys.LoginLogId = saleServer.WriteSalesLog(log);
            }
            else
            {
                sys = null;
            }
            return(sys);
        }