public virtual JsonResult Login() { //if (!VerifyToken()) //{ // return ResultUtils.Fail(app_senre, msg_box); //} string username = RequestHelper.GetFormString("username"); string password = RequestHelper.GetFormString("password"); if (Utils.StrIsNullOrEmpty(username) || Utils.StrIsNullOrEmpty(password)) { return(ResultUtils.Error("账号或密码不能为空")); } if (Utils.IsValidMobile(username)) //判断是否是手机号码 { userid = NH.Service.Api.AuthService.GetInstance().LoginUp(username, password, 1); //手机号码 } else { userid = NH.Service.Api.AuthService.GetInstance().LoginUp(username, password, 0); //用户名 } if (userid > 0) { Entity.Model.Token token = base.GetToken(); return(ResultUtils.Success(new { userId = token.UserID, timeStamp = token.Timestamp, platform = token.Platform, token = token.TokenStr })); } return(ResultUtils.Fail("登录失败")); }
/// <summary> /// 获取用户Token /// </summary> /// <param name="tokenBase64">Base64 Token字符串</param> /// <returns></returns> public Entity.Model.Token GetToken(string tokenBase64) { Entity.Model.Token token = NH.Service.Api.TokenService.GetInstance().GetToken(tokenBase64); if (token != null) { userid = token.UserID; platform = (Regplatform)token.Platform; } return(token); }
/// <summary> /// 重置密码 /// </summary> /// <param name="req"></param> /// <returns></returns> public virtual JsonResult ResetPassword(ResetPasswordReq req) { if (string.IsNullOrEmpty(req.phone)) { return(ResultUtils.Fail("手机号码或用户名不能为空")); } if (string.IsNullOrEmpty(req.code)) { return(ResultUtils.Fail("验证码不能为空")); } if (string.IsNullOrEmpty(req.password)) { return(ResultUtils.Fail("密码不能为空")); } SubmitCodeReq mod = new SubmitCodeReq() { phone = req.phone, code = req.code }; int ret = NH.Service.VerifyService.Instance().SubmitCode(mod); if (ret == 0) { return(ResultUtils.Success("验证码过期")); } else if (ret == -1) { return(ResultUtils.Fail("用户不存在")); } else if (ret == -2) { return(ResultUtils.Fail("手机号码未注册")); } userid = NH.Service.Api.AuthService.GetInstance().ResetPassword(req); if (userid > 0) { Entity.Model.Token token = base.GetToken(); return(ResultUtils.Success(new { userId = token.UserID, timeStamp = token.Timestamp, platform = token.Platform, token = token.TokenStr })); } return(ResultUtils.Fail("重置密码失败")); }
public virtual ActionResult Register(RegisterReq mod) { lock (lockhelper) { if (string.IsNullOrEmpty(mod.phone)) { return(ResultUtils.Error("手机号码不能为空")); } else if (!Utils.IsValidMobile(mod.phone)) { return(ResultUtils.Error("手机号码格式有误")); } if (string.IsNullOrEmpty(mod.code)) { return(ResultUtils.Error("验证码不能为空")); } else if (mod.code.Trim().Length != 6) { return(ResultUtils.Error("验证码有误")); } else { } if (string.IsNullOrEmpty(mod.username)) { mod.username = mod.phone; } if (string.IsNullOrEmpty(mod.password)) { return(ResultUtils.Error("密码不能为空")); } userid = NH.Service.Api.AuthService.GetInstance().Regieste(mod); if (userid > 0) { Entity.Model.Token token = base.GetToken(); return(ResultUtils.Success(new { userId = token.UserID, timeStamp = token.Timestamp, platform = token.Platform, token = token.TokenStr })); } return(ResultUtils.Fail("注册失败")); } }
/// <summary> /// 验证 Token /// </summary> /// <param name="verify">是否必须验证</param> /// <param name="isApp">是否是APP</param> /// <returns></returns> public bool VerifyToken(bool verify, bool isApp) { string tokenBase64 = RequestHelper.GetString("token"); if (!isApp && Utils.StrIsNullOrEmpty(tokenBase64)) { tokenBase64 = Utils.GetCookie("token"); } Entity.Model.Token token = NH.Service.Api.TokenService.GetInstance().GetToken(tokenBase64); if (verify) { if (token == null || !token.IsValidSecretKey || token.UserID <= 0) { app_senre = -1; msg_box = "服务器繁忙,请重新登录"; return(false); } else if (token.IsOverdue) { app_senre = 999; msg_box = "服务器繁忙,请重新登录"; return(false); } app_senre = 1; userid = token.UserID; platform = token.Platform; } else { if (token != null && token.IsValidSecretKey && token.UserID > 0 && !token.IsOverdue) { app_senre = 1; userid = token.UserID; platform = token.Platform; } } return(true); }