Пример #1
0
    private void setLogOut()
    {
        tblUserLog objUserLog = new tblUserLog();

        objUserLog.LoadByPrimaryKey((int)Session[appFunctions.Session.UserLogID.ToString()]);
        if (objUserLog.RowCount > 0)
        {
            objUserLog.AppLogOutDate = DateTime.Now;
            objUserLog.Save();
            objUserLog = null;
        }
        Session[appFunctions.Session.UserLogID.ToString()] = "";
    }
Пример #2
0
    //protected void btnCancel_Click(object sender, System.EventArgs e)
    //{
    //    Response.Redirect("Default.aspx");
    //}


    protected void SaveLog(bool IsSuccess)
    {
        objUserLog = new tblUserLog();
        objUserLog.AddNew();

        if (Session[appFunctions.Session.UserID.ToString()] != null)
        {
            objUserLog.AppUserID = (int)Session[appFunctions.Session.UserID.ToString()];
        }

        objUserLog.AppLogInDate  = DateTime.Now;
        objUserLog.AppIPAddress  = Request.UserHostAddress.ToString();
        objUserLog.AppIsSuccess  = IsSuccess;
        objUserLog.AppLogOutDate = DateTime.Now;
        objUserLog.Save();
        Session[appFunctions.Session.UserLogID.ToString()] = objUserLog.AppUserLogID;
        objUserLog = null;
    }
Пример #3
0
        public LoginModel loginUser(LoginModel model)
        {
            LoginModel _LoginModel = new LoginModel();

            try
            {
                List <tblUserRole> _tblUserRole = new List <tblUserRole>();
                bool    FirstLog = false;
                tblUser _tblUser = new tblUser();

                tblUserLog _tblUserLog = new tblUserLog();
                model.Username = model.Username.Trim();
                model.Password = model.Password.Trim();
                model.Password = EncryptUtil.EncryptString(model.Password);


                model.Username = model.Username.ToLower();



                _tblUser = _ItblUserRepository.Get(x => x.Email.ToLower() == model.Username && x.Password == model.Password && x.IsActive == true && x.IsBlocked == false).FirstOrDefault();


                if (_tblUser != null)
                {
                    _tblUser.tblUserRole    = null;
                    _tblUser.InvalidAttempt = 0;
                    _ItblUserRepository.Update(_tblUser);
                    List <tblRole> _tblUserRole2 = _ItblUserRoleRepository.Get(x => x.FKUser == _tblUser.PKUser && x.IsActive == true).Select(s =>
                                                                                                                                              s.tblRole
                                                                                                                                              ).ToList();

                    foreach (var data in _tblUserRole2)
                    {
                        tblUserRole temp = new tblUserRole();
                        temp.tblRole = data;
                        temp.FKRole  = data.PKRole;

                        _tblUserRole.Add(temp);
                    }


                    _tblUserLog.LoginSuccess = true;
                    _tblUserLog.FKUser       = _tblUser.PKUser;

                    lastLogin = _ItblUserLogRepository.Get(x => x.UserName == _tblUser.Email && x.LoginSuccess == true).ToList();
                    if (lastLogin != null && lastLogin.Count > 0 && _tblUser.IsChangePassword == true)
                    {
                        FirstLog = true;
                    }
                    else
                    {
                        FirstLog = false;
                    }
                }

                else
                {
                    _tblUser = _ItblUserRepository.Get(x => x.Email.ToLower() == model.Username && x.Password == model.Password && x.IsActive == true && x.IsBlocked == true).FirstOrDefault();


                    if (_tblUser != null)
                    {
                        _LoginModel.ErrorMessage = "Your account has been blocked. Please contact to the administrator!";
                    }
                    else
                    {
                        _tblUser = _ItblUserRepository.Get(x => x.Email.ToLower() == model.Username).FirstOrDefault();


                        if (_tblUser != null)
                        {
                            _tblUser.tblUserRole    = null;
                            _tblUserLog.FKUser      = _tblUser.PKUser;
                            _tblUser.InvalidAttempt = _tblUser.InvalidAttempt + 1;
                            _ItblUserRepository.Update(_tblUser);
                        }
                        _tblUserLog.LoginSuccess = false;
                        _LoginModel.ErrorMessage = "Invalid Username Or Password";
                    }
                }


                _tblUserLog.UserName  = model.Username;
                _tblUserLog.Password  = model.Password;
                _tblUserLog.LoginTime = DateTime.Now;
                _tblUserLog.IPAddress = context.HttpContext.Connection.RemoteIpAddress.ToString();
                _tblUserLog.Origin    = model.Origin;
                _tblUserLog.IsActive  = true;
                _ItblUserLogRepository.Add(_tblUserLog);
                if (_tblUser != null && _tblUser.InvalidAttempt > 3)
                {
                    tblUser _tblUser1 = new tblUser();

                    _tblUser1 = _ItblUserRepository.Get(x => x.Email.ToLower() == model.Username).FirstOrDefault();



                    if (_tblUser1 != null)
                    {
                        _tblUser1.IsBlocked  = true;
                        _tblUser.IsBlocked   = true;
                        _tblUser.tblUserRole = null;
                        _ItblUserRepository.Update(_tblUser1);
                    }
                }

                if (_tblUser != null)
                {
                    _tblUser.IsActive    = FirstLog;
                    _tblUser.tblUserRole = _tblUserRole;
                    if (_tblUserLog.LoginSuccess == false)
                    {
                        _tblUser = null;
                    }
                    else
                    {
                        _tblUser.Password = null;
                    }
                }

                _LoginModel.Users = _tblUser;
                if (_LoginModel.ErrorMessage != null && _LoginModel.ErrorMessage.Length > 0)
                {
                    _LoginModel.Users = null;
                }
                return(_LoginModel);
            }
            catch (Exception ex)
            {
                _LoginModel.ErrorMessage = ex.Message;
                log.Fatal("login:", ex);
                throw ex;
            }
        }