public Result<LoginUser> Login(LoginUser loginUser) { userDataAccess.Login(); return new Result<LoginUser>(); }
public async Task<JsonResult> Login(LoginUser loginUser) { #if DEBUG loginUser.WxOpenId = debugOpenId;//"oOGoot0O0nEuP4uEHdNLQyNpGnwM";//"oOGootzpwe38CkQSTj00wyHhKSMk";// #endif var jsonResult = new JsonResult(); try { //logger.Info(JsonHelper.ToJson(loginUser)); //check验证码 var user = UserService.GetUserByWxOpenId(loginUser.WxOpenId); if (user == null||user.UserId==0) { //创建用户 var openId = loginUser.WxOpenId; var accesstoken = AccessTokenContainer.TryGetToken(AppId, AppSecret); var wxUser = CommonApi.GetUserInfo(accesstoken, openId); if (!string.IsNullOrEmpty(wxUser.headimgurl)) { wxUser.headimgurl = wxUser.headimgurl.Substring(0, wxUser.headimgurl.Length - 1) + "96"; } var userModel = new UserModel() { CreateTime = DateTime.Now, WxOpenId = openId, WxHeadUrl = wxUser.headimgurl, WxNickName = wxUser.nickname, Status = 1 }; if (UserService.Insert(userModel) > 0) { user = UserService.GetUserByWxOpenId(loginUser.WxOpenId); } else { logger.Error("用户信息insert失败:"+JsonHelper.ToJson(userModel)); } } else { if (!string.IsNullOrEmpty(user.Mobile) && loginUser.Mobile != user.Mobile) { jsonResult.Data = new { IsSuccess = false, Msg = "一个微信账号只能绑定一个手机号。" }; return jsonResult; } } //logger.Info(JsonHelper.ToJson(user)); if (UserService.CheckMobileCaptcha(user.UserId, loginUser.Mobile, loginUser.Captcha)) { //更新验证码状态 UserService.UpdateUserCaptchaStatus(user.UserId, loginUser.Mobile); //logger.Info(1); //将用户的手机号与weixinid绑定 UserService.UpdateMobileUserByWxOpenId(loginUser.Mobile, loginUser.WxOpenId); //logger.Info(2); var result = UserManager.FindByNameAsync(loginUser.Mobile); //logger.Info(3); //用户禁用不让登陆 if (result != null && user.Status == 1) { //logger.Info(JsonHelper.ToJson(result)); await SignInAsync(result.Result, true); //logger.Info(4); jsonResult.Data = new { IsSuccess = true }; } else { jsonResult.Data = new { IsSuccess = false, Msg = "您的用户已被禁用" }; } } else { jsonResult.Data = new { IsSuccess = false, Msg = "验证码不正确" }; } } catch (Exception ex) { logger.Error(ex); } return jsonResult; }