Example #1
0
        /// <summary>
        /// 用户注册
        /// </summary>
        public ReturnResult <long> RegisterUser(TdMemberDataContract member)
        {
            if (string.IsNullOrWhiteSpace(member.UserName))
            {
                return(new ReturnResult <long>(101, 0, "参数异常,用户名不允许为空"));
            }
            if (string.IsNullOrWhiteSpace(member.Password))
            {
                return(new ReturnResult <long>(102, 0, "参数异常,密码不允许为空"));
            }
            if (null != MemberRepository.Instance.GetMember(member.UserName))
            {
                return(new ReturnResult <long>(103, 0, "用户名已存在"));
            }

            member.RoleId        = Guid.Empty;
            member.RegTime       = DateTime.Now;
            member.LastLoginDate = DateTime.Now;
            member.UserId        = Guid.NewGuid();
            member.Password      = member.Password.GetEncrypt();
            member.NickName      = member.UserName;

            if (MemberRepository.Instance.InsertMember(member))
            {
                //FormsAuthenticationWrapper.Instance.SetAuthCookie(member.UserKeyId.ToString(), true);
                return(new ReturnResult <long>(member.UserKeyId));
            }
            return(new ReturnResult <long>(104, 0, "注册失败"));
        }
        public bool InsertMember(TdMemberDataContract meber)
        {
            string sql = @"INSERT INTO TdMember(UserId,RoleId,Gender,CaseCount,LastLoginDate,RegTime,IsApproved,LoginCount,CreditCount,AttentionCount,Email,RegIP,LastLoginIp,QQ,Phone,Location,WebSite,FaceImg,UserName,Password,NickName)
						   VALUES(@UserId,@RoleId,@Gender,@CaseCount,@LastLoginDate,@RegTime,@IsApproved,@LoginCount,@CreditCount,@AttentionCount,@Email,@RegIP,@LastLoginIp,@QQ,@Phone,@Location,@WebSite,@FaceImg,@UserName,@Password,@NickName);SELECT @@IDENTITY"                        ;

            var _parm = new SqlParameter[] {
                new SqlParameter("@UserId", meber.UserId),
                new SqlParameter("@RoleId", meber.RoleId),
                new SqlParameter("@Gender", meber.Gender),
                new SqlParameter("@CaseCount", meber.CaseCount),
                new SqlParameter("@LastLoginDate", meber.LastLoginDate),
                new SqlParameter("@RegTime", meber.RegTime),
                //new SqlParameter("@Birthday", meber.Birthday),
                new SqlParameter("@IsApproved", meber.IsApproved),
                new SqlParameter("@LoginCount", meber.LoginCount),
                new SqlParameter("@CreditCount", meber.CreditCount),
                new SqlParameter("@AttentionCount", meber.AttentionCount),
                new SqlParameter("@Email", meber.Email),
                new SqlParameter("@RegIP", meber.RegIP),
                new SqlParameter("@LastLoginIp", meber.LastLoginIp),
                new SqlParameter("@QQ", meber.QQ),
                new SqlParameter("@Phone", meber.Phone),
                new SqlParameter("@Location", meber.Location),
                new SqlParameter("@WebSite", meber.WebSite),
                new SqlParameter("@FaceImg", meber.FaceImg),
                new SqlParameter("@UserName", meber.UserName),
                new SqlParameter("@Password", meber.Password),
                new SqlParameter("@NickName", meber.NickName)
            };

            meber.UserKeyId = Convert.ToInt64(SqlHelper.ExecuteScalar(SqlHelper.GetConnSting(), CommandType.Text, sql, _parm));

            return(meber.UserKeyId > 0);
        }
Example #3
0
        public ReturnResult <OauthToken> CreateAccessToken(TdMemberDataContract memberInfo)
        {
            if (null == memberInfo || memberInfo.UserKeyId < 1)
            {
                return(new ReturnResult <OauthToken>(101, null, "参数memberInfo错误"));
            }

            OauthToken accessToken = new OauthToken();

            accessToken.ClientID    = 10001;         //目前默认为10001
            accessToken.UserKeyId   = memberInfo.UserKeyId;
            accessToken.AccessToken = CreateToken();
            accessToken.Expires     = DateTime.Now.Epoch() + ACCESS_TOKEN_EXPIRES;
            accessToken.Scope       = "all";      //权限默认
            accessToken.User        = memberInfo;

            RefreshTokenDataContract refreshToken = new RefreshTokenDataContract();

            refreshToken.ClientID     = accessToken.ClientID;
            refreshToken.UserKeyID    = accessToken.UserKeyId;
            refreshToken.RefreshToken = CreateToken();
            refreshToken.Expires      = DateTime.Now.Epoch() + REFRESH_TOKEN_EXPIRES;

            accessToken.RefreshToken = refreshToken.RefreshToken;

            TokenRepository.Instance.InsertAccessToken(accessToken);
            TokenRepository.Instance.InsertRefreshToken(refreshToken);

            return(new ReturnResult <OauthToken>(accessToken));
        }
        public TdMemberDataContract GetMember(long userKeyId)
        {
            string sql = @"SELECT UserKeyId,UserId,RoleId,UserName,Password,Email,IsApproved,LastLoginDate,RegTime,NickName,RegIP,Gender,LastLoginIp,Birthday,QQ,Phone,Location,
						   WebSite,LoginCount,CaseCount,FaceImg,CreditCount,AttentionCount FROM tdMember WHERE UserKeyId=@UserKeyId"                        ;

            TdMemberDataContract member = null;

            using (var dr = SqlHelper.ExecuteReader(SqlHelper.GetConnSting(), CommandType.Text, sql, new SqlParameter("@UserKeyId", userKeyId)))
            {
                member = EntityHelper.GetEntity <TdMemberDataContract>(dr);
            }

            return(member);
        }
Example #5
0
        public JsonResult Regsiter(string userName, string passWord)
        {
            var user = new TdMemberDataContract();

            user.UserName    = userName;
            user.Password    = passWord;
            user.RegIP       = System.Web.HttpContext.Current.Request.GetIp();
            user.LastLoginIp = user.RegIP;

            var result = memberService.RegisterUser(user);

            if (result.Code != 0)
            {
                return(Json(result));
            }
            return(Json(tokenService.CreateAccessToken(user)));
        }