Пример #1
0
        public DataResult EditMobile(string newMobile, string msgCode, string password)
        {
            var result = new DataResult("false", "密码错误", null, null);
            var vCode  = VerifyCode.GetDetail(newMobile);

            if (vCode == null || vCode.ExpireDt < DateTime.Now || vCode.Code != msgCode)
            {
                result = new DataResult("false", "验证码错误或过期", null, null);
            }
            else
            {
                if (User.Search(mobile: newMobile).Count() > 0)
                {
                    result = new DataResult("false", "号码已使用", null, null);
                }
                else
                {
                    var user = User.GetDetail(mobile: Common.LoginUser.Mobile);
                    if (user != null && user.InUsed && PasswordHelper.ComparePasswords(user.Password, password))
                    {
                        user.Mobile = newMobile;
                        user.Save();
                        Logout();
                        LoginSuccess(user);
                        result = new DataResult("true", "修改成功", null, null);
                    }
                }
            }
            return(result);
        }
Пример #2
0
        public static DataResult SendSms(string mobile, int sourceType)
        {
            string     source = sourceType == 1 ? "微信" : sourceType == 2 ? "安卓" : sourceType == 3 ? "苹果" : "";
            DataResult result = new DataResult("false", "获取失败", null, null);

            try
            {
                if (!string.IsNullOrEmpty(source))
                {
                    VerifyCode vCode = null;//  VerifyCode.Search(mobile, null, DateTime.Now).FirstOrDefault();
                    if (vCode != null)
                    {
                        result = new DataResult("false", "短信未过期", null, null);
                    }
                    else
                    {
                        vCode          = new VerifyCode();
                        vCode.Code     = GetRandomNumber(6);
                        vCode.CreateDt = DateTime.Now;
                        vCode.ExpireDt = vCode.CreateDt.AddMinutes(10);
                        vCode.Source   = source;
                        vCode.Mobile   = mobile;
                        AliSmsHelper.SendSmsRegist(mobile, vCode.Code);
                        vCode.Save();
                        result = new DataResult("true", "获取成功", null, null);
                    }
                }
            }
            catch (Exception e)
            {
                result = new DataResult("false", "系统异常" + e.Message, null, null);
            }
            return(result);
        }
Пример #3
0
        public DataResult SetPassword(string mobile, string password, string msgCode)
        {
            var result = new DataResult("false", "当前用户不存在", null, null);
            var vCode  = VerifyCode.GetDetail(mobile);

            if (vCode == null || vCode.ExpireDt < DateTime.Now || vCode.Code != msgCode)
            {
                result = new DataResult("false", "验证码错误或过期", null, null);
            }
            else
            {
                var user = User.GetDetail(null, null, mobile, null);
                if (user != null)
                {
                    user.Password = PasswordHelper.CreateDbPassword(password);
                    user.Save();
                    result = new DataResult("true", "设置成功", null, null);
                }
            }
            return(result);
        }
Пример #4
0
        public static DataResult LoginByMsgCode(string mobile, string msgCode)
        {
            var result = new DataResult("false", "验证码错误", null, null);
            var vCode  = VerifyCode.GetDetail(mobile);

            if (vCode == null || vCode.ExpireDt < DateTime.Now || vCode.Code != msgCode)
            {
                result = new DataResult("false", "验证码错误或过期", null, null);
            }
            else
            {
                var user     = User.GetDetail(null, null, mobile, null);
                var userInfo = Asp.GetSession("OAuthUserInfo") as OAuthUserInfo;
                if (user == null)
                {
                    result = new DataResult("false", "手机号码未在平台绑定", null, null);
                }
                else
                {
                    if (user.NickName.IsNullOrEmpty())
                    {
                        user.NickName = userInfo.nickname;
                    }
                    if (user.Photo.IsNullOrEmpty())
                    {
                        user.Photo = userInfo.headimgurl;
                    }

                    if (user.WechatOpenId.IsNullOrEmpty())
                    {
                        user.WechatOpenId = userInfo.openid;
                    }
                    LoginSuccess(user);
                    Logger.LogToDb("登录成功", LogLevel.Info, mobile);
                    result = new DataResult("true", "登录成功", null, null);
                }
            }
            return(result);
        }
Пример #5
0
        public DataResult BindTel(string mobile, string password, string msgCode, string inviterId)
        {
            var result = new DataResult("true", "绑定成功", null, null);
            var vCode  = VerifyCode.GetDetail(mobile);

            if (vCode == null || vCode.ExpireDt < DateTime.Now)
            {
                result = new DataResult("false", "验证码已过期", null, null);
            }
            else if (vCode.Code != msgCode)
            {
                result = new DataResult("false", "验证码错误", null, null);
            }
            else
            {
                var user = App.DAL.User.Get(mobile: mobile);
                if (user != null)
                {
                    result = new DataResult("false", "当前手机号码已被其他人使用", null, null);
                }
                else
                {
                    //OAuthAccessTokenResult oauthResult = OAuthApi.GetAccessToken(WeChatHelper.AppID, WeChatHelper.AppSecret, userToken);
                    //OAuthUserInfo userInfo = OAuthApi.GetUserInfo(oauthResult.access_token, oauthResult.openid);
                    OAuthUserInfo userInfo = Asp.GetSession("OAuthUserInfo") as OAuthUserInfo;
                    user              = new User();
                    user.Name         = mobile;
                    user.Password     = PasswordHelper.CreateDbPassword(password);
                    user.NickName     = userInfo.nickname;
                    user.WechatOpenId = userInfo.openid;
                    user.Photo        = userInfo.headimgurl;
                    user.Mobile       = mobile;
                    user.Phone        = mobile;
                    user.CreateDt     = DateTime.Now;
                    user.InUsed       = true;
                    user.Gender       = userInfo.sex == 1 ? "男" : "女";
                    user.Roles        = new List <RoleType>()
                    {
                        RoleType.Customer
                    };
                    user.Save();
                    LoginSuccess(user);

                    if (inviterId != "-1" && DESEncrypt.DecryptDES(inviterId) != inviterId)//这个解密失败,会返回传入的值
                    {
                        inviterId = DESEncrypt.DecryptDES(inviterId);
                        User inviter = User.Get(inviterId.ToInt32());
                        if (inviter != null)
                        {
                            //注册成功,才记录邀请记录
                            Invite invite = new Invite();
                            invite.InviterID     = inviter.ID;
                            invite.InviteeID     = user.ID;
                            invite.InviteeMobile = mobile;
                            invite.Sts           = InviteStatus.New;
                            invite.Source        = InviteSource.WeiXin;
                            invite.CreateDt      = DateTime.Now;
                            invite.RegistDt      = user.CreateDt;
                            invite.Save();
                            result = new DataResult("true", "受邀,绑定成功", null, null);
                        }
                    }
                }
            }
            return(result);
        }