/// <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); }