Exemple #1
0
        public IActionResult signIn(string UserName, string Password)
        {
            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
            {
                return(new JsonResult(new { Message = "نام کاربری یا کلمه عبور نمی تواند خالی باشد", context = "error", page = "/" }));
            }
            Utility.Message message = _userContext.CheckUserPass(UserName, Password);
            //نام کاربری یا کلمه عبور نادرست است
            if (message.Equals(Utility.Message.WrongUserPass))
            {
                //faildLogs ذخیره در
                Faild_Log faild = new Faild_Log()
                {
                    DateTime_In = DateTime.Now.ToString(),
                    UserName    = UserName,
                    Password    = Password
                };
                _faildLoginContext.Add(faild);
                return(new JsonResult(new { Message = Utility.GetMessage(message), Context = "error", Page = "/" }));
            }

            //احراز هویت صحیح می باشد
            else if (message.Equals(Utility.Message.Success))
            {
                //loginLogs ذخیره در
                Login_Log login = new Login_Log()
                {
                    UserID = _userContext.FindByUserName(UserName).UserID,
                    DateIn = DateTime.Now.Month.ToString("00") + "/" + DateTime.Now.Day.ToString("00") + "/" + DateTime.Now.Year.ToString("00"),
                    TimeIn = DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00") + " " + (DateTime.Now.ToString().ToLower().Contains("am") ? "AM" : "PM")
                };
                _loginContext.Add(login);
                string Token = Utility.CreateToken(50);
                // HttpContext.Session.SetString(Token, _userContext.FindByUserName(UserName).UserID.ToString());

                Utility.UserType userType = _userContext.GetUserType(UserName, Password);
                if (userType.Equals(Utility.UserType.Admin))
                {
                    return(new JsonResult(new { Page = "/AdminPage", token = Token }));
                }
                else if (userType.Equals(Utility.UserType.User))
                {
                    return(new JsonResult(new { Page = "/UserPage", token = Token, userID = _userContext.FindByUserName(UserName).UserID.ToString() }));
                }
                else
                {
                    return(new JsonResult(new { Message = "خطای ناشناس", Context = "Warning", Page = "/" }));
                }
            }
            else
            {
                return(new JsonResult(new { Message = "خطای ناشناس", Contex = "Warning", Page = "/" }));
            }
        }
Exemple #2
0
 public void CreateLoginLog(Login_Log log)
 {
     using (chargebitEntities db = new chargebitEntities())
     {
         if (log != null)
         {
             if (!string.IsNullOrEmpty(log.LoginIP) && log.UserId > 0 && log.LoginTime > 0)
             {
                 db.Login_Log.Add(log);
                 db.SaveChanges();
             }
         }
     }
 }
Exemple #3
0
        private ActionResult RedirectToLocal(string loginEmail, string returnUrl)
        {
            UserManagement umgt = new UserManagement(loginEmail);

            if (umgt.CurrentLoginUser != null)
            {
                Login_Log log = new Login_Log()
                {
                    UserId = umgt.CurrentLoginUser.User.Id, LoginTime = KMBit.Util.DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), LoginIP = Request.UserHostAddress
                };
                if (!umgt.CurrentLoginUser.User.Enabled)
                {
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    log.Message = "账户被锁定,不能登陆系统,请联系管理员";
                    log.Succeed = false;
                    umgt.CreateLoginLog(log);
                    return(RedirectToAction("LoginError", "Account", new { message = "账户被锁定,不能登陆系统,请联系管理员" }));
                }
                log.Message = "";
                log.Succeed = true;
                umgt.CreateLoginLog(log);
                if (umgt.CurrentLoginUser.IsAdmin)
                {
                    return(RedirectToAction("Index", "Admin"));
                }
                else
                {
                    return(RedirectToAction("Index", "Agent"));
                }
            }

            if (Url.IsLocalUrl(returnUrl))
            {
                return(Redirect(returnUrl));
            }

            if (string.IsNullOrEmpty(loginEmail))
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Index", "Home"));
        }