示例#1
0
 /// <summary>
 /// 创建会员账号业务
 /// </summary>
 /// <param name="userCode">会员账号</param>
 /// <param name="password">指定登录密码</param>
 /// <param name="refereeCode">指定推荐人</param>
 /// <param name="userId">指定会员ID</param>
 public UserCreationProvider(string userCode, string password, string refereeCode, UserVoucherType uvt = UserVoucherType.手机号)
 {
     this._userCode    = userCode;
     this._password    = password;
     this._refereeCode = refereeCode;
     this._uvt         = uvt;
     this.Vouchers     = new List <IUserVoucher>();
 }
示例#2
0
        public bool Login(int client_source, string client_system, string device_id, string ip_address, string session_id, string clientVersion, int appid)
        {
            var fac = UserModuleFactory.GetUserModuleInstance();

            if (fac == null)
            {
                Alert(ResultType.系统异常, "加载用户模块失败");
                return(false);
            }
            try
            {
                UserVoucherType uvt = xUtils.GetVoucherType(this._user_code);
                this.User = fac.GetUserByVoucher(this._user_code, uvt);
            }
            catch (ApplicationException ex)
            {
                Alert(ResultType.非法操作, "无效的登录账号");
                Log.Error($"无效的登录账号[{this._user_code}]", ex);
                return(false);
            }
            catch (Exception exp)
            {
                Log.Error("登录异常", exp);
                Alert(ResultType.系统异常, "系统异常");
                return(false);
            }
            if (this.User == null)
            {
                Alert(ResultType.无效数据类型, "用户未注册");
                return(false);
            }
            if (this.User.Status != UserStatus.已激活)
            {
                Alert(ResultType.非法操作, $"账户{this.User.Status.ToString()}");
                return(false);
            }
            var lockResult = this.User.IsLocked(Winner.User.Interface.Lock.LockRight.登录);

            if (lockResult.IsLocked)
            {
                Alert(ResultType.非法操作, lockResult.Reason);
                return(false);
            }
            if (loginType == LoginType.LOGIN_BY_PASSWORD || loginType == LoginType.密码登录)
            {
                if (!IgnorePassword && !this.User.CheckLoginPassword(_password))
                {
                    Alert(ResultType.非法操作, this.User.ErrorInfo.Message);
                    return(false);
                }
            }
            else if (loginType == LoginType.短信验证码登录)
            {
                SmsValidateProvider smsValid = new SmsValidateProvider(this.User.MobileNo, SmsValidateType.登录验证码);
                if (!smsValid.ValidateCode(_password))
                {
                    Alert(ResultType.非法操作, smsValid.PromptInfo);
                    return(false);
                }
            }
            else
            {
                Alert(ResultType.无效数据类型, "无效的登录方式");
                return(false);
            }
            SaveUserDevice(this.User.UserId, device_id, client_system, client_source);
            //this.Token = xUtils.EncryptAccessToken(this.User.UserId, this.User.UserCode, appid);

            UserTokenProvider utp = new UserTokenProvider(appid, this.User.UserId, null, device_id, this._scope);

            if (!utp.GenerateUserToken())
            {
                Alert(utp.PromptInfo);
                return(false);
            }
            this.OAuthUser = utp.OAuthUser;
            this.Token     = utp.OAuthUser.Token;


            //Tauth_Session daSession = new Tauth_Session
            var daSession = DaoFactory.Tauth_Session();

            daSession.Client_Source  = client_source;
            daSession.Client_System  = client_system;
            daSession.Device_Id      = device_id;
            daSession.Ip_Address     = ip_address;
            daSession.Session_Id     = session_id;
            daSession.Status         = 1;
            daSession.User_Id        = this.User.UserId;
            daSession.Token          = this.Token;
            daSession.Client_Version = clientVersion;

            if (!daSession.Insert())
            {
                Alert(ResultType.系统异常, "保存登录会话失败");
                return(false);
            }
            Logined();
            return(true);
        }
示例#3
0
        public bool Register()
        {
            string[] array = new string[2];
            string   plainText;

            if (!xUtils.RsaDecrypt(_model.AuthCode, out plainText))
            {
                Alert("OpenID解密失败");
                return(false);
            }
            int pos = plainText.IndexOf('_');

            array[0] = plainText.Substring(0, pos);
            array[1] = plainText.Substring(pos + 1);
            long timestamp;

            if (!long.TryParse(array[0], out timestamp))
            {
                Alert("OpenID解密失败");
                return(false);
            }
            long currentTime = xUtils.GetCurrentTimeStamp();

            if (currentTime - timestamp > 120)
            {
                Alert("请求已过期");
                return(false);
            }
            string openID = array[1];
            SmsValidateProvider smsValidate = new SmsValidateProvider(_model.MobileNo, SmsValidateType.绑定手机号);

            if (!smsValidate.ValidateCode(_model.ValidateCode))
            {
                Alert(smsValidate.PromptInfo);
                return(false);
            }
            var fac = UserModuleFactory.GetUserModuleInstance();

            if (fac == null)
            {
                Alert("系统模块异常");
                return(false);
            }
            if (!Enum.TryParse(_model.Platform, true, out ThirdpartyLoginPlatform platform))
            {
                Alert($"无效的第三方登录平台[{_model.Platform}]");
                return(false);
            }
            UserVoucherType uvt            = (UserVoucherType)platform;
            IUser           thirdpartyUser = fac.GetUserByVoucher(openID, uvt);

            if (thirdpartyUser == null)
            {
                IUser user = fac.GetUserByMobileno(_model.MobileNo);
                if (user == null)
                {
                    var voucher = fac.GetVoucherObject();
                    voucher.AllowLogin  = true;
                    voucher.IsValid     = true;
                    voucher.Status      = 1;
                    voucher.UserCode    = _model.MobileNo;
                    voucher.VoucherType = UserVoucherType.手机号;
                    UserCreationProvider ucp = new UserCreationProvider(openID, null, _model.RefereeCode, uvt);
                    ucp.Vouchers.Add(voucher);
                    if (!ucp.AddUser(_model.NickName ?? xUtils.GetDefaultUserName(_model.MobileNo), _model.Avatar))
                    {
                        Alert(ucp.PromptInfo);
                        return(false);
                    }
                    user = ucp.User;
                }
                else
                {
                    var voucher = fac.GetVoucherObject();
                    voucher.AllowLogin  = true;
                    voucher.IsValid     = true;
                    voucher.Status      = 1;
                    voucher.UserCode    = openID;
                    voucher.VoucherType = uvt;
                    if (!voucher.Save(user.UserId))
                    {
                        Alert((ResultType)503, "已有账号绑定第三方登录失败");
                        return(false);
                    }
                    user.Refresh();
                }
                this.User = user;
            }
            else
            {
                var thirdpartyVoucher = thirdpartyUser.Vouchers?.Find(it => it.VoucherType == uvt);
                if (thirdpartyVoucher != null)
                {
                    Alert((ResultType)409, $"该账号[{_model.MobileNo}]已绑定{platform.GetDisplayText()}");
                    return(false);
                }
                var voucher = fac.GetVoucherObject();
                voucher.AllowLogin  = true;
                voucher.IsValid     = true;
                voucher.Status      = 1;
                voucher.UserCode    = _model.MobileNo;
                voucher.VoucherType = UserVoucherType.手机号;
                if (!voucher.Save(thirdpartyUser.UserId))
                {
                    Alert((ResultType)503, "已有账号绑定第三方登录失败");
                    return(false);
                }
                thirdpartyUser.Refresh();
                this.User = thirdpartyUser;
            }
            return(true);
        }
示例#4
0
        /// <summary>
        /// 检查UserCode是否已存在
        /// </summary>
        /// <returns></returns>
        private static bool IsUserCodeAlreadyExist(string code, UserVoucherType uvt, IUserFactory fac)
        {
            IUser user = fac.GetUserByVoucher(code, uvt);

            return(user != null);
        }