示例#1
0
        private async Task <OperationResult> Login(string userName, string registKey, LoginDevice loginDevice, string clientVersion)
        {
            //更新最后一次登录的RegistKey
            var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.UserName == userName);

            if (theUser == null)
            {
                return(new OperationResult(OperationResultType.ValidError, "数据错误", null));
            }

            if (theUser.RegistKey != registKey)
            {
                theUser.RegistKey = registKey;
                await UserInfoRepo.UpdateAsync(theUser);
            }

            //变更登录信息
            await ResetToken(theUser, loginDevice, clientVersion);

            var loginInfo = new UserTokenDto()
            {
                Id       = theUser.Id,
                NickName = theUser.SysUser.NickName,
                HeadPic  = theUser.HeadPic,
                Sex      = theUser.Sex,
                Token    = theUser.Token
            };

            return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="registKey">极光registKey</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <param name="type">登录方式</param>
        /// <returns></returns>
        public async Task <OperationResult> Login(string userName, string password, string registKey, LoginDevice loginDevice, string clientVersion, int type)
        {
            userName.CheckNotNullOrEmpty("userName");
            password.CheckNotNullOrEmpty("password");

            SysUser sUser = await UserManager.FindByNameAsync(userName);

            if (sUser == null)
            {
                return(new OperationResult(OperationResultType.ValidError, "用户不存在", 0));
            }
            if (sUser.IsLocked)
            {
                return(new OperationResult(OperationResultType.ValidError, "您的账号已被冻结,请联系客服", 0));
            }
            if (type == 2)
            {
                //验证码
                var severCode = GetValidateCode(userName, CodeType.临时密码);
                if (severCode == null || severCode.Code != password)
                {
                    return(new OperationResult(OperationResultType.ValidError, "临时密码错误", 0));
                }
            }
            else
            {
                if (!await UserManager.CheckPasswordAsync(sUser, password))
                {
                    return(new OperationResult(OperationResultType.ValidError, "用户名或密码错误", null));
                }
            }
            if (sUser.UserType != UserType.App用户)
            {
                return(new OperationResult(OperationResultType.QueryNull, "用户不存在", null));
            }
            //更新最后一次登录的RegistKey
            var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.UserName == userName);

            if (theUser.RegistKey != registKey)
            {
                theUser.RegistKey = registKey;
                await UserInfoRepo.UpdateAsync(theUser);
            }

            //变更登录信息
            await ResetToken(theUser, loginDevice, clientVersion);

            var loginInfo = new UserTokenDto()
            {
                Id       = theUser.Id,
                NickName = theUser.SysUser.NickName,
                HeadPic  = theUser.HeadPic,
                Sex      = theUser.Sex,
                PhoneNo  = theUser.SysUser.PhoneNumber,
                Token    = theUser.Token
            };

            //return new OperationResult(OperationResultType.Success, "登录成功", sUser);
            return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
        }
        /// <summary>
        /// 三方登录
        /// </summary>
        /// <param name="thirdKey">三方key</param>
        /// <param name="thirdProvider">微博?QQ?微信?</param>
        /// <param name="loginDevice">登录设备 IOS?Android?</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <param name="registKey">极光推送Key</param>
        /// <returns></returns>
        public async Task <OperationResult> LoginByThird(string thirdKey, ThirdProvider thirdProvider, LoginDevice loginDevice, string clientVersion, string registKey = "")
        {
            var thirdUser = SysUserLoginRepo.Entities.SingleOrDefault(m => m.ProviderKey == thirdKey && m.ThridProvider == thirdProvider);

            if (thirdUser == null)
            {
                var     userName = "******" + DateTime.Now.ToString("yyyyMMddhhffff");
                SysUser sUser    = new SysUser()
                {
                    UserName = userName,
                    NickName = userName,
                    UserType = UserType.App用户,
                };
                UserInfoRepo.UnitOfWork.TransactionEnabled = true;
                await UserManager.CreateAsync(sUser);

                var userInfo = new UserInfo()
                {
                    SysUser   = sUser,
                    IsDeleted = false,
                    Sex       = Sex.限,
                };
                await UserInfoRepo.InsertAsync(userInfo);

                thirdUser = new SysUserLogin()
                {
                    ProviderKey   = thirdKey,
                    ThridProvider = thirdProvider,
                    User          = sUser,
                };
                await SysUserLoginRepo.InsertAsync(thirdUser);

                await UserInfoRepo.UnitOfWork.SaveChangesAsync();
            }

            var theUser = UserInfoRepo.Entities.SingleOrDefault(m => m.SysUser.Id == thirdUser.User.Id);

            if (theUser.RegistKey != registKey)
            {
                theUser.RegistKey = registKey;
                await UserInfoRepo.UpdateAsync(theUser);
            }

            //变更登录信息
            await ResetToken(theUser, loginDevice, clientVersion);

            var loginInfo = new UserTokenDto()
            {
                Id       = theUser.Id,
                NickName = theUser.SysUser.NickName,
                HeadPic  = theUser.HeadPic,
                Sex      = theUser.Sex,
                Token    = theUser.Token
            };

            return(CdkxResult.Success(loginInfo));
        }
示例#4
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="registKey">极光registKey</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> Login(string userName, string password, string registKey, LoginDevice loginDevice, string clientVersion)
        {
            userName.CheckNotNullOrEmpty("userName");
            password.CheckNotNullOrEmpty("password");

            SysUser sUser = await UserManager.FindByNameAsync(userName);

            var result = await UserManager.CheckPasswordAsync(sUser, password);

            if (sUser == null || sUser.UserType != UserType.App用户)
            {
                return(new OperationResult(OperationResultType.QueryNull, "用户不存在", null));
            }
            else if (sUser.IsLocked)
            {
                return(new OperationResult(OperationResultType.ValidError, "该账号已被冻结,请联系客服。", null));
            }
            else if (!await UserManager.CheckPasswordAsync(sUser, password))
            {
                return(new OperationResult(OperationResultType.ValidError, "用户名或密码错误", null));
            }
            else
            {
                //更新最后一次登录的RegistKey
                var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.UserName == userName);

                if (theUser == null)
                {
                    return(new OperationResult(OperationResultType.ValidError, "数据错误", null));
                }

                if (theUser.RegistKey != registKey)
                {
                    theUser.RegistKey = registKey;
                    await UserInfoRepo.UpdateAsync(theUser);
                }

                //变更登录信息
                await ResetToken(theUser, loginDevice, clientVersion);

                var loginInfo = new UserTokenDto()
                {
                    Id       = theUser.Id,
                    NickName = theUser.SysUser.NickName,
                    HeadPic  = theUser.HeadPic,
                    Sex      = theUser.Sex,
                    Token    = theUser.Token
                };
                return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
            }
        }
示例#5
0
        /// <summary>
        /// 修改用户昵称和头像
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="nickName"></param>
        /// <param name="headPic"></param>
        /// <returns></returns>
        public async Task <OperationResult> EditUserInfo(int userId, string nickName, string headPic)
        {
            UserInfoRepo.UnitOfWork.TransactionEnabled = true;
            var info = UserInfoRepo.GetByKey(userId);

            info.HeadPic = headPic;
            await UserInfoRepo.UpdateAsync(info);

            var sys = info.SysUser;

            sys.NickName = nickName;
            var result = await SysUserRepo.UpdateAsync(sys);

            await UserInfoRepo.UnitOfWork.SaveChangesAsync();

            return(new OperationResult(OperationResultType.Success, "修改成功"));
        }
        /// <summary>
        /// 重置用户Token有效期
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> ResetToken(UserInfo user, LoginDevice loginDevice, string clientVersion)
        {
            Operator oper = new Operator()
            {
                UserId         = user.Id.ToString(),
                UserName       = user.SysUser.UserName,
                LoginDevice    = loginDevice,
                PhoneNo        = user.SysUser.PhoneNumber,
                ClientVersion  = clientVersion,
                ValidatePeriod = DateTime.Now.AddDays(30),//默认30天有效期
                UserDatas      = new Dictionary <string, object>()
            };
            string strAuth = oper.ToJsonString();

            user.Token = DesHelper.Encrypt(strAuth, OSharp.Core.Constants.BodeAuthDesKey);

            await UserInfoRepo.UpdateAsync(user);

            return(new OperationResult(OperationResultType.Success, "重置成功", user.Token));
        }
示例#7
0
        /// <summary>
        /// 重置用户Token有效期
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> ResetToken(UserInfo user, LoginDevice loginDevice, string clientVersion)
        {
            Operator oper = new Operator()
            {
                UserId         = user.Id.ToString(),
                UserName       = user.SysUser.UserName,
                LoginDevice    = loginDevice,
                PhoneNo        = user.SysUser.PhoneNumber,
                ClientVersion  = clientVersion,
                ValidatePeriod = DateTime.Now.AddDays(30)//默认30天有效期
            };
            string authDesKey = "bodeauth";
            string strAuth    = oper.ToJsonString();

            user.Token = DesHelper.Encrypt(strAuth, authDesKey);

            await UserInfoRepo.UpdateAsync(user);

            return(new OperationResult(OperationResultType.Success, "重置成功"));
        }
示例#8
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="phoneNo">手机号</param>
        /// <param name="password">密码</param>
        /// <param name="registKey">极光registKey</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> Login(string phoneNo, string password, string registKey, LoginDevice loginDevice, string clientVersion)
        {
            phoneNo.CheckNotNullOrEmpty("phoneNo");
            phoneNo.CheckNotNullOrEmpty("password");

            SysUser sUser = await UserManager.FindByNameAsync(phoneNo);

            var result = await UserManager.CheckPasswordAsync(sUser, password);

            if (!await UserManager.CheckPasswordAsync(sUser, password))
            {
                return(new OperationResult(OperationResultType.ValidError, "用户名或密码错误", null));
            }
            else
            {
                //更新最后一次登录的RegistKey
                var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.PhoneNumber == phoneNo);

                if (theUser.RegistKey != registKey)
                {
                    theUser.RegistKey = registKey;
                    await UserInfoRepo.UpdateAsync(theUser);
                }

                //变更登录信息
                await ResetToken(theUser, loginDevice, clientVersion);

                var loginInfo = new UserTokenDto()
                {
                    Id       = theUser.Id,
                    NickName = theUser.SysUser.NickName,
                    HeadPic  = theUser.HeadPic,
                    Token    = theUser.Token
                };
                return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
            }
        }