예제 #1
0
        private static UserInfoBigMo GetRegisteUserInfo(string value, string passWord, RegLoginType type)
        {
            var sysInfo = MemberShiper.AppAuthorize;

            var userInfo = new UserInfoBigMo
            {
                app_source  = sysInfo.AppSource,
                app_version = sysInfo.AppVersion,
                tenant_id   = sysInfo.TenantId
            };

            if (type == RegLoginType.Mobile)
            {
                userInfo.mobile = value;
            }
            else
            {
                userInfo.email = value;
            }

            if (!string.IsNullOrEmpty(passWord))
            {
                userInfo.pass_word = Md5.EncryptHexString(passWord);
            }

            SetBaseInfo(userInfo);
            return(userInfo);
        }
예제 #2
0
        private static UserInfoBigMo GetRegisteUserInfo(string value, string passWord, RegLoginType type)
        {
            var sysInfo = MemberShiper.AppAuthorize;

            var userInfo = new UserInfoBigMo
            {
                create_time = DateTime.Now.ToUtcSeconds(),
                app_source  = sysInfo.AppSource,
                app_version = sysInfo.AppVersion
            };

            if (type == RegLoginType.Email)
            {
                userInfo.email  = value;
                userInfo.status = (int)MemberStatus.WaitConfirm;
            }
            else
            {
                userInfo.mobile = value;
            }

            if (type != RegLoginType.MobileCode)
            {
                userInfo.pass_word = Md5.EncryptHexString(passWord);
            }

            return(userInfo);
        }
예제 #3
0
        /// <summary>
        ///  添加用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <IdResp <string> > AddUser(UserInfoBigMo user)
        {
            if (!string.IsNullOrEmpty(user.email))
            {
                var checkEmailRes = await InsContainer <IPortalServiceProxy> .Instance.CheckIfCanReg(RegLoginType.Email, user.email);

                if (!checkEmailRes.IsSuccess())
                {
                    return(new IdResp <string>().WithResp(checkEmailRes));
                }
            }
            if (!string.IsNullOrEmpty(user.mobile))
            {
                var checkMobileRes = await InsContainer <IPortalServiceProxy> .Instance.CheckIfCanReg(RegLoginType.Mobile, user.mobile);

                if (!checkMobileRes.IsSuccess())
                {
                    return(new IdResp <string>().WithResp(checkMobileRes));
                }
            }

            user.InitialBaseFromContext();

            return(await UserInfoRep.Instance.Add(user));
        }
예제 #4
0
        private static UserInfoBigMo GetRegisterUserInfo(string value, string passWord, RegLoginType type)
        {
            var sysInfo  = CoreAppContext.Identity;
            var userInfo = new UserInfoBigMo();

            userInfo.InitialBaseFromContext();

            switch (type)
            {
            case RegLoginType.Mobile:
                userInfo.mobile = value;
                break;

            case RegLoginType.Email:
                userInfo.email = value;
                break;

            case RegLoginType.ThirdName:
                userInfo.nick_name = value;
                break;
            }

            if (!string.IsNullOrEmpty(passWord))
            {
                userInfo.pass_word = Md5.EncryptHexString(passWord);
            }

            return(userInfo);
        }
예제 #5
0
        private static UserTokenResp LoginExcute(UserInfoBigMo user)
        {
            MemberEvents.TriggerUserLoginEvent(user, MemberShiper.AppAuthorize);
            var checkRes = CheckMemberStatus(user.status);

            return(checkRes.IsSuccess()
                ? BindOauthAndGenerateUserToken(user, MemberAuthorizeType.User)
                : checkRes.ConvertToResult <UserTokenResp>());
        }
예제 #6
0
        private static UserTokenResp GenerateUserToken(UserInfoBigMo user, MemberAuthorizeType authType)
        {
            var tokenStr = string.Concat(user.id, "|", (int)authType, "|", DateTime.Now.ToUtcSeconds());
            var token    = MemberShiper.GetToken(tokenSecret, tokenStr);

            return(new UserTokenResp()
            {
                token = token, user = user.ConvertToMo()
            });
        }
예제 #7
0
        public static UserInfoBigMo MapToUserInfo(this AddUserReq req)
        {
            var userInfo = new UserInfoBigMo
            {
                mobile    = req.mobile,
                nick_name = req.nick_name,
                email     = req.email
            };

            return(userInfo);
        }
예제 #8
0
 private static UserTokenResp BindOauthAndGenerateUserToken(UserInfoBigMo user, MemberAuthorizeType authType)
 {
     if (MemberShiper.IsAuthenticated &&
         MemberShiper.Identity.AuthenticationType == (int)MemberAuthorizeType.OauthUserTemp)
     {
         var OauthUserId = MemberShiper.Identity.Id;
         if (OauthUserId > 0)
         {
             OauthUserRep.Instance.UpdateUserIdByOauthId(OauthUserId, user.id);
         }
     }
     return(GenerateUserToken(user, authType));
 }
예제 #9
0
        private async Task <PortalTokenResp> LoginFinallyExecute(UserInfoBigMo user,
                                                                 PortalAuthorizeType authType, bool isFromThirdBind = false, SocialPlatform plat = SocialPlatform.None)
        {
            Resp <UserIdentity> identityRes;

            switch (authType)
            {
            case PortalAuthorizeType.Admin:     //  登录时默认只有admin,不会出现 superAdmin

                var adminRes = await AdminInfoRep.Instance.GetAdminByUId(user.id);

                if (!adminRes.IsSuccess())
                {
                    return new PortalTokenResp()
                           {
                               ret = adminRes.ret, msg = "管理员账号/密码错误!"
                           }
                }
                ;

                identityRes = InitialAdminIdentity(adminRes.data, plat);
                break;

            case PortalAuthorizeType.User:
                identityRes = InitialUserIdentity(user, plat);
                break;

            default:
                return(new PortalTokenResp(RespTypes.ParaError, "账号/密码错误!"));
            }

            if (!identityRes.IsSuccess())
            {
                return(new PortalTokenResp().WithResp(identityRes));
            }

            if (isFromThirdBind)
            {
                var bindRes = await BindTempOauthUserToUser(user.id);

                if (!bindRes.IsSuccess())
                {
                    return(new PortalTokenResp().WithResp(bindRes));
                }

                plat = bindRes.data;
            }

            PortalEvents.TriggerLoginEvent(identityRes.data, CoreAppContext.Identity);
            return(GeneratePortalToken(identityRes.data, plat));
        }
예제 #10
0
        /// <summary>
        ///  BigMo转化为Mo
        ///    主要防止直接返回BigMo附带用户密码,来源渠道等字段
        /// </summary>
        /// <param name="io"></param>
        /// <returns></returns>
        public static UserInfoMo ConvertToMo(this UserInfoBigMo io)
        {
            var userInfo = new UserInfoMo
            {
                email       = io.email,
                nick_name   = io.nick_name,
                mobile      = io.mobile,
                Id          = io.Id,
                create_time = io.create_time,

                status = io.status
            };

            return(userInfo);
        }
예제 #11
0
        /// <summary>
        /// 注册用户信息
        /// </summary>
        /// <param name="value">注册的账号信息</param>
        /// <param name="passWord">密码</param>
        /// <param name="passCode"> 验证码(手机号注册时需要 </param>
        /// <param name="type">注册类型</param>
        /// <returns></returns>
        public async Task <ResultMo <UserInfoMo> > RegisteUser(string value, string passWord, string passCode, RegLoginType type)
        {
            var checkRes = await CheckIfCanRegiste(type, value);

            if (!checkRes.IsSuccess())
            {
                return(checkRes.ConvertToResultOnly <UserInfoMo>());
            }

            // todo 检查验证码
            var userInfo = new UserInfoBigMo();

            if (type == RegLoginType.Email)
            {
                userInfo.email = value;
            }
            else
            {
                userInfo.mobile = value;
            }

            if (type != RegLoginType.MobileCode)
            {
                userInfo.pass_word = Md5.HalfEncryptHexString(passWord);
            }

            var idRes = await InsContainer <IUserInfoRep> .Instance.Insert(userInfo);

            if (!idRes.IsSuccess())
            {
                return(idRes.ConvertToResultOnly <UserInfoMo>());
            }

            userInfo.Id = idRes.id;
            MemberEvents.TriggerUserRegiteEvent(userInfo, MemberShiper.AppAuthorize);

            return(new ResultMo <UserInfoMo>(userInfo));
        }
예제 #12
0
        private static Resp <UserIdentity> InitialUserIdentity(UserInfoBigMo user, SocialPlatform fromPlat)
        {
            user.pass_word = null; //  不可传出

            var checkRes = CheckIdentityStatus(user.status);

            if (!checkRes.IsSuccess())
            {
                return(new Resp <UserIdentity>().WithResp(checkRes));
            }

            var identity = new UserIdentity
            {
                id     = user.id.ToString(),
                name   = user.nick_name ?? user.mobile ?? user.email,
                avatar = user.avatar,
                //from_plat = (int) fromPlat,

                auth_type = PortalAuthorizeType.User
            };

            return(new Resp <UserIdentity>(identity));
        }
예제 #13
0
        private async Task <PortalTokenResp> RegFinallyExecute(UserInfoBigMo user, PortalAuthorizeType authType,
                                                               bool isFromBind = false, SocialPlatform plat = SocialPlatform.None)
        {
            var idRes = await UserInfoRep.Instance.Add(user);

            if (!idRes.IsSuccess())
            {
                return(new PortalTokenResp().WithResp(idRes));
            }

            if (isFromBind)
            {
                var bindRes = await BindTempOauthUserToUser(user.id);

                if (!bindRes.IsSuccess())
                {
                    return(new PortalTokenResp().WithResp(bindRes)); //bindRes;
                }
                plat = bindRes.data;
            }

            user.pass_word = null;
            var identity = new UserIdentity()
            {
                auth_type = authType,

                id     = user.id.ToString(),
                name   = user.nick_name,
                avatar = user.avatar
            };

            PortalEvents.TriggerRegisterEvent(identity, plat, CoreAppContext.Identity);
            return(GeneratePortalToken(identity, plat));

            ;
        }
예제 #14
0
        /// <summary>
        /// 注册用户信息
        /// </summary>
        /// <param name="value">注册的账号信息</param>
        /// <param name="passCode">密码</param>
        /// <param name="type">注册类型</param>
        /// <param name="auInfo">注册的系统信息</param>
        /// <returns></returns>
        public async Task <ResultMo <UserInfoMo> > RegisteUser(string value, string passCode, RegLoginType type, SysAuthorizeInfo auInfo)
        {
            var checkRes = await CheckIfCanRegiste(type, value);

            if (!checkRes.IsSuccess)
            {
                return(checkRes.ConvertToResultOnly <UserInfoMo>());
            }

            var userInfo = new UserInfoBigMo();

            if (type == RegLoginType.Email)
            {
                userInfo.email = value;
            }
            else
            {
                userInfo.mobile = value;
            }

            if (type != RegLoginType.MobileCode)
            {
                userInfo.pass_word = Md5.HalfEncryptHexString(passCode);
            }

            var idRes = await Rep <IUserInfoRep> .Instance.Insert(userInfo);

            if (!idRes.IsSuccess)
            {
                return(idRes.ConvertToResultOnly <UserInfoMo>());
            }

            userInfo.Id = idRes.Id;
            // todo 触发新用户注册事件
            return(new ResultMo <UserInfoMo>(userInfo));
        }
예제 #15
0
 public static void TriggerUserRegiteEvent(UserInfoBigMo arg1, AppAuthorizeInfo arg2)
 {
     // todo  推送注册消息
 }
예제 #16
0
 public static void TriggerUserLoginEvent(UserInfoBigMo arg1, AppAuthorizeInfo arg2)
 {
     // todo  推送登录消息
 }