Exemplo n.º 1
0
 //public Member GetMember(DataSource ds)
 //{
 //    MemberId = ExecuteScalar<OAuth2Member, int>(ds, "MemberId", P("Type", Type) & P("UserId", UserId));
 //    if (MemberId > 0)
 //        return Member.GetById(ds, MemberId);
 //    return null;
 //}
 //public DataStatus BindMember(DataSource ds, long memberId)
 //{
 //    MemberId = memberId;
 //    return Update(ds, ColumnMode.Include, "MemberId");
 //}
 //public Member BindMember(DataSource ds, string memberName)
 //{
 //    Member member = Member.GetByName(ds, memberName);
 //    if (member != null)
 //    {
 //        if (BindMember(ds, member.Id) == DataStatus.Success)
 //            return member;
 //    }
 //    return null;
 //}
 public static DataStatus Register(DataSource ds, string type, string userId, Member member, RegisterType rt)
 {
     if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(userId))
     {
         ds.Begin();
         try
         {
             Member temp = Member.GetByType(ds, member, rt);
             if (temp == null)
             {
                 DataStatus status = member.Insert(ds);
                 if (status != DataStatus.Success)
                 {
                     ds.Commit();
                     return(status);
                 }
                 else
                 {
                     temp = member;
                 }
             }
             else
             {
                 if (rt != RegisterType.Mobile && !string.Equals(temp.Password, member.Password.MD5()))
                 {
                     ds.Commit();
                     return(DataStatus.Exist);
                 }
             }
             OAuth2Member user = new OAuth2Member()
             {
                 Type     = type,
                 UserId   = userId,
                 MemberId = temp.Id
             };
             if (user.Update(ds, ColumnMode.Include, "MemberId") != DataStatus.Success)
             {
                 if (user.Insert(ds) != DataStatus.Success)
                 {
                     throw new Exception();
                 }
             }
             ds.Commit();
             return(DataStatus.Success);
         }
         catch (Exception)
         {
             ds.Rollback();
             return(DataStatus.Failed);
         }
     }
     else
     {
         return(DataStatus.ExistOther);
     }
 }
Exemplo n.º 2
0
        protected override IPayOrder GetPayOrder(string provider)
        {
            string openId = null;

            M.OAuth2Member member = M.OAuth2Member.GetByUserPay(DataSource, provider, User.Identity.Id);
            if (member != null)
            {
                openId = member.UserId;
            }
            return(PayRecord.Create(DataSource, User.Identity.Id, openId, "充值", provider, Money.Parse(Request.Form["Money"]), 0, string.Empty));
        }
Exemplo n.º 3
0
        public void Cb(string type)
        {
            string target = Request.QueryString["target"];

            if (string.IsNullOrEmpty(target))
            {
                target = GetUrl("/");
            }
            OAuth2Provider provider = GetProvider(type);

            if (provider != null)
            {
                OAuth2TokenAccess token = provider.Access() as OAuth2TokenAccess;
                M.OAuth2Member    user  = provider.GetUserInfo(token);
                if (!string.IsNullOrEmpty(user.UserId))
                {
                    M.Member      member;
                    M.LoginStatus status = M.OAuth2Member.Login(DataSource, type.ToLower(), user.UserId, ClientIp, out member);
                    if (status == M.LoginStatus.Success)
                    {
                        PassportAuthentication.SetAuthCookie(true, false, member);
                        OnLogined(member.Id);
                        Refresh(target);
                    }
                    else
                    {
                        if (status == M.LoginStatus.NeedBind)
                        {
                            this["Oauth2Type"]   = user.Type;
                            this["Oauth2UserId"] = user.UserId;
                            this["Target"]       = target;
                            this["Sms"]          = SMSCaptchaSection.GetSection();
                            Render("oauth2.html");
                        }
                        else
                        {
                            Redirect(GetUrl("/login"));
                        }
                    }
                }
                else
                {
                    Redirect(GetUrl("/login"));
                }
            }
            else
            {
                Redirect(GetUrl("/login"));
            }
        }