Beispiel #1
0
        /// <summary>
        /// 尝试将使用用户名密码登陆系统
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="passWord">密码</param>
        /// <param name="userip">用户IP</param>
        /// <returns>返回是否成功登陆,若失败则返回出错信息</returns>
        public static IMethodResult SignIn(String userName, String passWord, String userip)
        {
            UserEntity user  = null;
            String     error = TryGetUserByUsernameAndPassword(userName, passWord, out user);

            if (!String.IsNullOrEmpty(error))
            {
                return(MethodResult.FailedAndLog(error));
            }

            if (AdminManager.InternalCheckPermission(user.Permission, PermissionType.HttpJudge))
            {
                return(MethodResult.FailedAndLog("You can not login a httpjudge account!"));
            }

            try
            {
                Int32 unreadMailCount = UserMailManager.InternalCountUserUnReadMails(user.UserName);

                UserBrowserStatus.SetCurrentUserBrowserStatus(user.UserName, user.Permission, unreadMailCount);
                UserSubmitStatus.InitLastSubmitTime(user.UserName);
                UserCurrentStatus.SetCurrentUserStatus(user);

                UpdateLoginInfomation(userName, userip);
            }
            catch (System.Exception ex)
            {
                return(MethodResult.Failed(ex.Message));
            }

            return(MethodResult.SuccessAndLog("User sign in"));
        }
        /// <summary>
        /// 尝试评测机登录
        /// </summary>
        /// <param name="serverID">评测机ID</param>
        /// <param name="secretKey">评测机密钥</param>
        /// <param name="userip">用户IP</param>
        /// <param name="error">错误信息</param>
        /// <returns>是否登录成功</returns>
        public static Boolean TryJudgeServerLogin(String serverID, String secretKey, String userip, out String error)
        {
            if (!ConfigurationManager.EnableJudgerInterface)
            {
                error = "Judger interface is disabled!";
                return(false);
            }

            UserEntity user = null;

            error = UserManager.TryGetUserByUsernameAndPassword(serverID, secretKey, out user);

            if (!String.IsNullOrEmpty(error))
            {
                return(false);
            }

            if (user.Permission != PermissionType.HttpJudge)
            {
                error = "You do not have httpjudge privilege!";
                return(false);
            }

            try
            {
                UserManager.UpdateLoginInfomation(serverID, userip);
                UserCurrentStatus.SetCurrentUserStatus(user);
                JudgeOnlineStatus.SetJudgeStatus(serverID);
            }
            catch { }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// 用户登出系统
        /// </summary>
        public static void SignOut()
        {
            String userName = UserManager.CurrentUserName;

            UserCurrentStatus.RemoveCurrentUserStatus();
            UserBrowserStatus.RemoveCurrentUserBrowserStatus();
            UserSubmitStatus.RemoveLastSubmitTime(userName);
            UserMailCache.RemoveUserUnReadMailCountCache(userName);
        }
Beispiel #4
0
        /// <summary>
        /// 用户注销
        /// </summary>
        /// <returns>操作后的结果</returns>
        public ActionResult Logout()
        {
            String userName = UserManager.CurrentUserName;

            UserCurrentStatus.RemoveCurrentUserStatus();
            UserBrowserStatus.RemoveCurrentUserBrowserStatus();
            UserSubmitStatus.RemoveLastSubmitTime(userName);
            UserMailCache.RemoveUserUnReadMailCountCache(userName);

            return(RedirectToRefferer());
        }
Beispiel #5
0
        /// <summary>
        /// 替换系统认证模型
        /// </summary>
        /// <param name="context">HttpContext</param>
        /// <remarks>应放在Global.asax.cs的Application_AuthenticateRequest时执行</remarks>
        public static void ReplaceFormAuthenticateModel(HttpContext context)
        {
            UserStatus user = UserCurrentStatus.ReplaceFormAuthenticateModel(context);

            if (user != null && !AdminManager.InternalCheckPermission(user.Permission, PermissionType.HttpJudge))
            {
                Int32 unreadMailCount = UserMailManager.InternalCountUserUnReadMails(user.UserName);

                UserBrowserStatus.SetCurrentUserBrowserStatus(user.UserName, user.Permission, unreadMailCount);
            }
        }