コード例 #1
0
        public ActionResult LoginOn(string username, string password, string captcha)
        {
            LogonLogModel logEntity        = new LogonLogModel();
            var           OperatorProvider = new OperatorProvider(HttpContext);

            logEntity.LogType = DbLogType.Login.ToString();
            try
            {
                if (OperatorProvider.WebHelper.GetSession("session_verifycode").IsEmpty() || Md5.md5(captcha.ToLower(), 16) != OperatorProvider.WebHelper.GetSession("session_verifycode"))
                {
                    throw new Exception("验证码错误");
                }
                UserModel userEntity = UserService.LoginOn(username, Md5.md5(password, 32));
                if (userEntity != null)
                {
                    if (userEntity.EnabledMark == 1)
                    {
                        throw new Exception("账号被锁定,禁止登录");
                    }
                    OperatorModel operatorModel = new OperatorModel();
                    operatorModel.UserId             = userEntity.Id;
                    operatorModel.Account            = userEntity.Account;
                    operatorModel.RealName           = userEntity.RealName;
                    operatorModel.HeadIcon           = userEntity.HeadIcon;
                    operatorModel.RoleId             = userEntity.RoleId;
                    operatorModel.LoginIPAddress     = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                    operatorModel.LoginIPAddressName = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                    OperatorProvider.AddCurrent(operatorModel);
                    logEntity.Account     = userEntity.Account;
                    logEntity.RealName    = userEntity.RealName;
                    logEntity.Description = "登陆成功";
                    LogonLogService.WriteDbLog(logEntity, operatorModel.LoginIPAddress, operatorModel.LoginIPAddressName);
                    return(Content(new AjaxResult {
                        state = ResultType.success.ToString(), message = "登录成功"
                    }.ToJson()));
                }
                else
                {
                    throw new Exception("用户名或密码错误");
                }
            }
            catch (Exception ex)
            {
                logEntity.Account     = username;
                logEntity.RealName    = username;
                logEntity.Description = "登录失败," + ex.Message;
                LogonLogService.WriteDbLog(logEntity, HttpContext.Connection.RemoteIpAddress.ToString(), HttpContext.Connection.RemoteIpAddress.ToString());
                return(Content(new AjaxResult {
                    state = ResultType.error.ToString(), message = ex.Message
                }.ToJson()));
            }
        }
コード例 #2
0
        public ActionResult LoginOut()
        {
            var OperatorProvider = new OperatorProvider(HttpContext);

            LogonLogService.WriteDbLog(new LogonLogModel
            {
                LogType     = DbLogType.Exit.ToString(),
                Account     = OperatorProvider.GetCurrent().Account,
                RealName    = OperatorProvider.GetCurrent().RealName,
                Description = "安全退出系统",
            }, HttpContext.Connection.RemoteIpAddress.ToString(), HttpContext.Connection.RemoteIpAddress.ToString());
            OperatorProvider.WebHelper.ClearSession();
            OperatorProvider.RemoveCurrent();
            return(RedirectToAction("Index", "Login"));
        }
コード例 #3
0
ファイル: APIController.cs プロジェクト: nxzzkj/lazyiot
        public JsonResult LoginOut()
        {
            AjaxResult error = new AjaxResult {
                state = ResultType.error.ToString(), message = "退出登录失败"
            };
            AjaxResult success = new AjaxResult {
                state = ResultType.success.ToString(), message = "退出登录成功"
            };

            LogonLogService.WriteDbLog(new LogonLogModel
            {
                LogType     = DbLogType.Exit.ToString(),
                Account     = OperatorFlowProvider.Provider.GetCurrent().Account,
                RealName    = OperatorFlowProvider.Provider.GetCurrent().RealName,
                Description = "安全退出系统",
            });
            Session.Abandon();
            Session.Clear();
            OperatorFlowProvider.Provider.RemoveCurrent();
            return(Json(success));
        }
コード例 #4
0
ファイル: APIController.cs プロジェクト: nxzzkj/lazyiot
        public JsonResult Login(loginModel model)
        {
            string     username = model.username, password = model.password, viewId = model.viewId, projId = model.projId;
            AjaxResult error = new AjaxResult {
                state = ResultType.error.ToString(), message = "登录失败"
            };
            AjaxResult success = new AjaxResult {
                state = ResultType.success.ToString(), message = "登录成功"
            };
            var           result    = error.SetMsg("禁止登录");
            LogonLogModel logEntity = new LogonLogModel();

            logEntity.LogType = DbLogType.Login.ToString();
            try
            {
                ScadaFlowProjectModel Project = null;
                if (viewId != null && viewId != "" && viewId != "0")
                {
                    ScadaFlowViewModel view = ViewServer.GetByWhere(" where  ViewId='" + viewId + "'").First();
                    if (view != null)
                    {
                        Project      = ProjectServer.GetByWhere(" where ProjectId='" + view.ProjectId + "'").First();
                        model.projId = Project.Id.ToString();
                        model.viewId = view.ViewId;
                    }
                    string nickname = "";
                    bool   isUser   = ProjectServer.LoginOn(username, password, Project.Id.ToString(), out nickname);
                    if (isUser == true)
                    {
                        OperatorModel operatorModel = new OperatorModel();
                        operatorModel.UserId             = 0;
                        operatorModel.Account            = username;
                        operatorModel.RealName           = nickname;
                        operatorModel.HeadIcon           = "";
                        operatorModel.RoleId             = 0;
                        operatorModel.LoginIPAddress     = Net.Ip;
                        operatorModel.LoginIPAddressName = Net.GetLocation(Net.Ip);
                        OperatorFlowProvider.Provider.AddCurrent(operatorModel);
                        logEntity.Account     = username;
                        logEntity.RealName    = nickname;
                        logEntity.Description = Project.Title + "(" + Project.Id + ")工程的 " + nickname + "登陆成功!";
                        LogonLogService.WriteDbLog(logEntity);
                        result      = success.SetMsg(nickname + "登陆成功");
                        result.data = Json(model).Data;

                        return(Json(result));
                    }
                    else
                    {
                        result = error.SetMsg("用户名或密码错误");
                        return(Json(result));
                    }
                }
                else
                {
                    logEntity.Account     = username;
                    logEntity.RealName    = username;
                    logEntity.Description = "登录失败,登录页面不存在";
                    LogonLogService.WriteDbLog(logEntity);
                    result = error.SetMsg(logEntity.Description);
                    return(Json(result));
                }
            }
            catch (Exception ex)
            {
                logEntity.Account     = username;
                logEntity.RealName    = username;
                logEntity.Description = "登录失败," + ex.Message;
                LogonLogService.WriteDbLog(logEntity);
                result = error.SetMsg(logEntity.Description);

                return(Json(result));
            }
        }