コード例 #1
0
ファイル: ActivatMember.aspx.cs プロジェクト: wgang10/ZYWeb
 /// <summary>
 /// 激活
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnActivat_Click(object sender, EventArgs e)
 {
     string msg = string.Empty;
     if (bll.ActivatMember(Int32.Parse(HidMemberID.Value), txtActivat.Text, ref msg))
     {
         lbMsg1.Text = "激活成功,请登录";
         lbMsg2.Text = "";
         lbMsg3.Text = "";
         lbMsg1.DataBind();
         //激活成功后直接登录
         Member modelMember = new Member();
         if (bll.LoginMember(Int32.Parse(HidMemberID.Value), ref msg, ref modelMember))
         {
             //设置session
             Session["MemberInfo"] = modelMember;
             //跳转登录
             Response.Redirect("MemberInfo.aspx");
         }
         else
         {
             lbMsg1.Text = msg;
             lbMsg2.Text = "";
             lbMsg3.Text = "";
         }
     }
     else
     {
         lbMsg1.Text = msg;
         lbMsg2.Text = "";
         lbMsg3.Text = "";
     }
 }
コード例 #2
0
ファイル: MemberOP.cs プロジェクト: wgang10/ZYWeb
        /// <summary>
        /// 删除会员
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool DeleteMember(Member model)
        {
            bool isSuccess = false;
            if (model != null)
            {
                var conf = new Configuration().Configure();
                ISession session = NHibernateHelper.GetSession();
                //配置NHibernate
                //在Configuration中添加HbmMapping
                conf.AddDeserializedMapping(NHibernateHelper.GetEntityMapping<Member>(), "MemberXML");
                //配置数据库架构元数据
                SchemaMetadataUpdater.QuoteTableAndColumns(conf);

                //建立SessionFactory
                var factory = conf.BuildSessionFactory();
                //打开Session做持久化数据
                using (session = factory.OpenSession())
                {
                    using (var tx = session.BeginTransaction())
                    {
                        session.Delete(model);
                        tx.Commit();
                        isSuccess = true;
                    }
                }
            }
            return isSuccess;
        }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: wgang10/ZYWeb
        /// <summary>
        /// 
        /// </summary>
        private void GetUserInfo()
        {
            lbLoginMessage.Text = "";
            lbLoginMessage.Visible = false;
            //获取Authorization Code
            if (Request.QueryString["code"] != null)
            {
                #region QQ登录
                try
                {
                    //参考地址 http://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token
                    //Step1:获取Authorization Code
                    //如果用户成功登录并授权,则会跳转到指定的回调地址,并在redirect_uri地址后带上Authorization Code和原始的state值
                    string code = Request.QueryString["code"].ToString();
                    string apppid = ConfigurationManager.AppSettings["appid"];
                    string appkey = ConfigurationManager.AppSettings["appkey"];
                    string callbackUrl = ConfigurationManager.AppSettings["callbackUrl"];
                    string state = ConfigurationManager.AppSettings["state"];
                    string Url = string.Format("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id={0}&client_secret={1}&code={2}&redirect_uri={3}"
                        , apppid, appkey, code, callbackUrl);

                    //Response.Redirect(Url);

                    //Step2:通过Authorization Code获取Access Token
                    WebRequest request = WebRequest.Create(Url);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream dataStream = response.GetResponseStream();
                    StreamReader reader = new StreamReader(dataStream);
                    string responseFromServer = reader.ReadToEnd();
                    //lbMessage2.Text = responseFromServer;
                    //如果成功返回,即可在返回包中获取到Access Token
                    //access_token=FE04************************CCE2&expires_in=7776000&refresh_token=88E4************************BE
                    /*
                     * access_token	授权令牌,Access_Token。
                     * expires_in	该access token的有效期,单位为秒。
                     * refresh_token	在授权自动续期步骤中,获取新的Access_Token时需要提供的参数。
                     */
                    //access_token=AEE7091E761C2A571991234AD280E6BA&expires_in=7776000

                    string access_token = responseFromServer.Substring(responseFromServer.IndexOf("=") + 1);
                    access_token = access_token.Substring(0, access_token.IndexOf("&"));
                    //Step3:使用Access Token来获取用户的OpenID
                    Url = string.Format("https://graph.qq.com/oauth2.0/me?access_token={0}", access_token);
                    request = WebRequest.Create(Url);
                    response = (HttpWebResponse)request.GetResponse();
                    dataStream = response.GetResponseStream();
                    reader = new StreamReader(dataStream);
                    responseFromServer = reader.ReadToEnd();
                    //lbMessage3.Text = responseFromServer;
                    //获取到用户OpenID,返回包如下:
                    //callback( {"client_id":"YOUR_APPID","openid":"YOUR_OPENID"} );
                    //callback( {"client_id":"100289171","openid":"1AC83BAA19BB2E892033E0C07C27AC24"} );
                    responseFromServer = responseFromServer.Replace("callback(", "").Replace(" );", "");
                    string openid=string.Empty;
                    var opid = JsonConvert.DeserializeObject<ObjOpenID>(responseFromServer);
                    if (opid != null)
                        openid = opid.openid;
                    //openid = responseFromServer.Replace(@"\", "").Substring(responseFromServer.IndexOf("openid") + 9);
                    //openid = openid.Substring(0, openid.IndexOf("}") - 1);
                    //lbMessage4.Text = "openid=" + openid;

                    //Step4:使用Access Token以及OpenID来访问和修改用户数据
                    //以调用get_user_info接口为例:
                    //发送请求到get_user_info的URL(请将access_token,appid等参数值替换为你自己的):
                    Url = string.Format("https://graph.qq.com/user/get_user_info?access_token={0}&oauth_consumer_key={1}&openid={2}", access_token, apppid, openid);
                    request = WebRequest.Create(Url);
                    response = (HttpWebResponse)request.GetResponse();
                    dataStream = response.GetResponseStream();
                    reader = new StreamReader(dataStream);
                    responseFromServer = reader.ReadToEnd();
                    reader.Close();
                    dataStream.Close();
                    response.Close();

                    var Juser = JsonConvert.DeserializeObject<ObjUser>(responseFromServer);
                    if (Juser != null)
                    {
                        //lbMessage5.Text = responseFromServer;
                        //string[] UserInfo = responseFromServer.Split(',');
                        //lbMessage6.Text = "昵称:" + UserInfo[2].Substring(UserInfo[2].IndexOf(":") + 2, UserInfo[2].Length - UserInfo[3].IndexOf(":") - 2);
                        //Image1.ImageUrl = UserInfo[3].Substring(UserInfo[3].IndexOf("http"), UserInfo[3].Length - UserInfo[3].IndexOf("http") - 1);
                        //Image2.ImageUrl = UserInfo[4].Substring(UserInfo[4].IndexOf("http"), UserInfo[4].Length - UserInfo[4].IndexOf("http") - 1);
                        //Image3.ImageUrl = UserInfo[5].Substring(UserInfo[5].IndexOf("http"), UserInfo[5].Length - UserInfo[5].IndexOf("http") - 1);

                        //(2)成功返回后,即可获取到用户数据:
                        /*
                        {
                               "ret":0,
                               "msg":"",
                               "nickname":"YOUR_NICK_NAME",
                               ...
                        }
                        */

                        divLogin.Visible = false;
                        divRegiste.Visible = false;
                        divLogined.Visible = true;
                        divUserInfo.Visible = true;

                        //用户登录
                        string msg = string.Empty;
                        Member modelMember = new Member();
                        modelMember.OpenId = openid;
                        //modelMember.Nickname = UserInfo[2].Substring(UserInfo[2].IndexOf(":") + 2, UserInfo[2].Length - UserInfo[3].IndexOf(":") - 2);
                        modelMember.Nickname = Juser.nickname;
                        //modelMember.PhotoURL = UserInfo[5].Substring(UserInfo[5].IndexOf("http"), UserInfo[5].Length - UserInfo[5].IndexOf("http") - 1);
                        modelMember.PhotoURL = Juser.figureurl;
                        if (bll.LoginMember(modelMember, ref msg))
                        {
                            IList<Member> members = bll.GetMemberByOpenID(openid);
                            if (members.Count > 0)
                            {
                                //modelMember.OpenId = openid;
                                //modelMember.Nickname = UserInfo[2].Substring(UserInfo[2].IndexOf(":") + 2, UserInfo[2].Length - UserInfo[3].IndexOf(":") - 2);
                                //modelMember.LoginTimes = members[0].LoginTimes;
                                //modelMember.LastLoginDateTime = members[0].LastLoginDateTime;
                                //modelMember.Integral = members[0].Integral;
                                //modelMember.PhotoURL = UserInfo[5].Substring(UserInfo[5].IndexOf("http"), UserInfo[5].Length - UserInfo[5].IndexOf("http") - 1);
                                Session["MemberInfo"] = members[0];
                                ZYSoft.Comm.UtilityLog.WriteInfo(string.Format("QQ账号 {0} 登录。{1}", members[0].Nickname, members[0].OpenId));
                                Response.Redirect("MemberInfo.aspx", true);

                                //lbNickname.Text = modelMember.Nickname;
                                //lbMemberNickname.Text = modelMember.Nickname;
                                //lbLoginTimes.Text = modelMember.LoginTimes.ToString();

                                //if (modelMember.LoginTimes<2)
                                //{
                                //    lbLastLoginDateTime.Text = "";
                                //}
                                //else
                                //{
                                //    lbLastLoginDateTime.Text = "上次登陆时间:"+modelMember.LastLoginDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");

                                //}
                                //lbIntegral.Text = modelMember.Integral.ToString();
                                //imgPhoto.ImageUrl =modelMember.PhotoURL;
                            }

                        }
                        else
                        {
                            lbLoginMessage.Text = msg;
                            lbLoginMessage.Visible = true;
                        }
                    }
                    //Random rdm = new Random(100);
                    //Response.Redirect("Default.aspx?x=" + rdm.Next().ToString());
                }
                catch (Exception ex)
                {
                    ZYSoft.Comm.UtilityLog.WriteError(ex.Message);
                    lbLoginMessage.Text = ex.Message;
                    lbLoginMessage.Visible = true;
                }
                #endregion
            }

            #region 使用第三方组件

            /*
            if (Request.QueryString["oauth_vericode"] != null)
            {
                var requestTokenKey = Session["requesttokenkey"].ToString();
                var requestTokenSecret = Session["requesttokensecret"].ToString();
                var verifier = Request.QueryString["oauth_vericode"];
                string key = ConfigurationManager.AppSettings["ConsumerKey"];
                string secret = ConfigurationManager.AppSettings["ConsumerSecret"];
                QzoneSDK.Qzone qzone = new QzoneSDK.Qzone(key, secret, requestTokenKey, requestTokenSecret, verifier);

                //这里需要将qzone.OAuthTokenKey, qzone.OAuthTokenSecret, qzone.OpenID 存储起来用于后面的API的访问
                QzoneSDK.Qzone qzone2 = new QzoneSDK.Qzone(key, secret, qzone.OAuthTokenKey, qzone.OAuthTokenSecret, string.Empty, true, qzone.OpenID);
                Session["qzonesdk"] = qzone2;

                qzone2 = Session["qzonesdk"] as QzoneSDK.Qzone;
                var currentUser = qzone2.GetCurrentUser();
                //this.lbMessage.Text = currentUser;
                var user = (BasicProfile)JsonConvert.Import(typeof(BasicProfile), currentUser);
                //if (null != currentUser)
                //{
                //this.result.Text = "成功登陆";
                //this.Nickname.Text = user.Nickname;
                //this.Figureurl.Text = user.Figureurl;
                //this.lbMoreInfo.Text="User's Msg:"+user.Msg+"User's Ret:"+user.Ret.ToString();
                //Image1.ImageUrl=user.Figureurl;
                //var list = Database.Instance.QzoneOauth.Where(x => x.OpenId == qzone2.OpenID).ToList();
                //if (list.Count > 0)
                //{
                //    QzoneOauth model = list[0];
                //    var newCookie = new HttpCookie("MemberID", model.UserId.ToString());
                //    newCookie.Expires = DateTime.Now.AddDays(10);
                //    Response.AppendCookie(newCookie);
                //    Session["QzoneOauth"] = model;
                //}
                //else
                //{
                //    User member = new User();
                //    member.Login = user.Nickname;
                //    member.Password = "******".Hash();
                //    member.ID = Guid.NewGuid();
                //    Database.Instance.InsertUser(member);
                //    QzoneOauth oauth = new QzoneOauth()
                //    {
                //        AccessTokenKey = qzone2.OAuthTokenKey,
                //        AccessTokenSecret = qzone2.OAuthTokenSecret,
                //        OpenId = qzone2.OpenID,
                //        ID = Guid.NewGuid(),
                //        UserId = member.ID,
                //    };
                //    Database.Instance.InsertQzoneOauth(oauth);
                //    var newCookie = new HttpCookie("MemberID", member.ID.ToString());
                //    newCookie.Expires = DateTime.Now.AddDays(10);
                //    Response.AppendCookie(newCookie);
                //    Session["QzoneOauth"] = oauth;
                //}
                //}
            }
            */
            #endregion
        }
コード例 #4
0
ファイル: Default.aspx.cs プロジェクト: wgang10/ZYWeb
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            lbLoginMessage.Visible = false;
            lbLoginMessage.Text = "";

            if (string.IsNullOrEmpty(txtLoginID.Text.Trim()) || string.IsNullOrEmpty(txtLoginPWD.Text.Trim()))
            {
                lbLoginMessage.Text = "账号和密码不能为空。";
                lbLoginMessage.Visible = true;
                return;
            }

            string msg=string.Empty;
            Member modelMember = new Member();
            if (bll.LoginMember(txtLoginID.Text, txtLoginPWD.Text, ref msg,ref modelMember))
            {
                ZYSoft.Comm.UtilityLog.WriteInfo(string.Format("账号 {0} 登陆成功。",txtLoginID.Text));
                Session["MemberInfo"] = modelMember;
                Response.Redirect("MemberInfo.aspx", true);
            }
            else
            {
                ZYSoft.Comm.UtilityLog.WriteInfo(string.Format("账号 {0} 登陆失败。{1}",txtLoginID.Text,msg));
                lbLoginMessage.Text = msg;
                lbLoginMessage.Visible = true;
            }
        }
コード例 #5
0
ファイル: UserBLL.cs プロジェクト: wgang10/ZYWeb
 /// <summary>
 /// 保存会员信息
 /// </summary>
 /// <param name="model"></param>
 /// <param name="Msg"></param>
 /// <returns></returns>
 public bool SaveMemberInfo(Member model,ref string Msg)
 {
     return true;
 }
コード例 #6
0
ファイル: UserBLL.cs プロジェクト: wgang10/ZYWeb
        /// <summary>
        /// 注册账号
        /// </summary>
        /// <param name="Nickname"></param>
        /// <param name="Email"></param>
        /// <param name="PassWord"></param>
        /// <param name="Msg"></param>
        /// <returns></returns>
        public bool RegistMember(string Nickname, string Email, string PassWord, ref string Msg ,ref int ID)
        {
            IList<Member> list = MemberOP.GetAllMemberByEmail(Email);
            if (list.Count > 0)
            {
                if (list[0].Status != 3)
                {
                    Msg = "邮箱已注册,请直接登录";
                    ID = list[0].Id;
                    return false;
                }
                else
                {
                    list[0].Nickname = Nickname;
                    list[0].LoginPWD = Comm.GlobalMethod.EncryptPWD(PassWord);
                    list[0].UpdateTime = DateTime.Now;
                    list[0].CreatTime = DateTime.Now;
                    list[0].VerifictionCode = Comm.GlobalMethod.GenerateVerifictionCode();
                    int limitMinutes = 30;
                    int.TryParse(ConfigurationManager.AppSettings["VerifictionCodeLimitMinutes"], out limitMinutes);
                    list[0].VerifictionCodeLimit = DateTime.Now.AddMinutes(limitMinutes);
                    Msg = String.Format("{0} [过期时间:{1:yyyy/MM/dd HH:mm:ss}]", list[0].VerifictionCode, list[0].VerifictionCodeLimit.Value);
                    ID = list[0].Id;
                    return MemberOP.UpdateMember(list[0]);
                }
            }
            else
            {
                Member model = new Member();

                model.Nickname = Nickname;
                model.Email = Email;
                model.LoginPWD = Comm.GlobalMethod.EncryptPWD(PassWord);
                model.Status = 3;//刚注册未验证
                model.LoginTimes = 0;
                model.Integral = 0;
                model.UpdateTime = DateTime.Now;
                model.CreatTime = DateTime.Now;
                model.VerifictionCode = Comm.GlobalMethod.GenerateVerifictionCode();
                int limitMinutes = 30;
                int.TryParse(ConfigurationManager.AppSettings["VerifictionCodeLimitMinutes"], out limitMinutes);
                model.VerifictionCodeLimit = DateTime.Now.AddMinutes(limitMinutes);
                model.Id = MemberOP.SaveMember(model);
                if (model.Id == -1)
                {
                    Msg = "注册失败!";
                    return false;
                }
                else
                {
                    Msg = String.Format("{0} [过期时间:{1:yyyy/MM/dd HH:mm:ss}]", model.VerifictionCode, model.VerifictionCodeLimit.Value);
                    ID = model.Id;
                    return true;
                }
            }
        }
コード例 #7
0
ファイル: UserBLL.cs プロジェクト: wgang10/ZYWeb
 /// <summary>
 /// 会员登录
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="Msg"></param>
 /// <returns></returns>
 public bool LoginMember(int ID, ref string Msg,ref Member model)
 {
     bool isSuccess = false;
     IList<Member> list = MemberOP.GetNormalMemberByID(ID);
     if (list.Count > 0)
     {
         list[0].LoginTimes += 1;
         //如果最后登录时间不是今天(也就是今天第一次登录)积分+10
         if (list[0].LastLoginDateTime.HasValue && list[0].LastLoginDateTime.Value.Date != DateTime.Now.Date && list[0].LastLoginDateTime <DateTime.Now)
         {
             list[0].Integral += 10;
         }
         list[0].LastLoginDateTime = list[0].CurrentLoginDateTime;
         list[0].CurrentLoginDateTime = DateTime.Now;
         list[0].UpdateTime = DateTime.Now;
         model = list[0];
         return MemberOP.UpdateMember(list[0]);
     }
     else
     {
         Msg = "会员不存在";//会员不存在
         return false;
     }
 }
コード例 #8
0
ファイル: UserBLL.cs プロジェクト: wgang10/ZYWeb
        /// <summary>
        /// 会员登录
        /// </summary>
        /// <param name="LoginID"></param>
        /// <param name="PWD"></param>
        /// <param name="Msg"></param>
        /// <returns></returns>
        public bool LoginMember(string LoginID, string PWD, ref string Msg,ref Member model)
        {
            bool isSuccess = false;
            IList<Member> list = MemberOP.GetNormalMemberByEmail(LoginID);
            if (list.Count > 0)
            {
                if (!list[0].LoginPWD.Trim().Equals(Comm.GlobalMethod.EncryptPWD(PWD)))
                {
                    Msg = "账号或密码错误";
                    return false;
                }

                list[0].LoginTimes += 1;
                //如果最后登录时间不是今天(也就是今天第一次登录)积分+10
                if (list[0].LastLoginDateTime.HasValue && list[0].LastLoginDateTime.Value.Date != DateTime.Now.Date && list[0].LastLoginDateTime < DateTime.Now)
                {
                    list[0].Integral += 10;
                }
                list[0].LastLoginDateTime = list[0].CurrentLoginDateTime;
                list[0].CurrentLoginDateTime = DateTime.Now;
                list[0].UpdateTime = DateTime.Now;
                model = list[0];
                return MemberOP.UpdateMember(list[0]);
            }
            else
            {
                Msg = "账号或密码错误";//账号不存在
                return false;
            }
        }
コード例 #9
0
ファイル: UserBLL.cs プロジェクト: wgang10/ZYWeb
        /// <summary>
        /// 会员登录
        /// </summary>
        /// <param name="Member"></param>
        /// <param name="Msg"></param>
        /// <returns></returns>
        public bool LoginMember(Member modelMember,ref string Msg)
        {
            bool isSuccess = false;
            try
            {
                IList<Member> list = MemberOP.GetMemberByOpenID(modelMember.OpenId);
                if (list.Count > 0)
                {
                    list[0].LoginTimes += 1;
                    list[0].Nickname = modelMember.Nickname;
                    //如果最后登录时间不是今天(也就是今天第一次登录)积分+10
                    if (list[0].LastLoginDateTime.Value.Date != DateTime.Now.Date && list[0].LastLoginDateTime <DateTime.Now)
                    {
                        list[0].Integral += 10;
                    }
                    list[0].LastLoginDateTime = list[0].CurrentLoginDateTime;
                    list[0].CurrentLoginDateTime = DateTime.Now;
                    list[0].UpdateTime = DateTime.Now;
                    list[0].PhotoURL = modelMember.PhotoURL;
                    isSuccess=MemberOP.UpdateMember(list[0]);
                }
                else
                {
                    Member model = new Member();
                    HistoryOfMemberUpdate modelHis = new HistoryOfMemberUpdate();
                    model.OpenId = modelMember.OpenId;
                    model.Nickname = modelMember.Nickname;
                    model.LastLoginDateTime = DateTime.Now;
                    model.CurrentLoginDateTime = DateTime.Now;
                    model.LoginTimes = 1;
                    model.Integral = 100;
                    model.Status = 0;
                    model.UpdateTime = DateTime.Now;
                    model.CreatTime = DateTime.Now;
                    model.PhotoURL = modelMember.PhotoURL;
                    modelHis.MemberId = MemberOP.SaveMember(model);
                    if (modelHis.MemberId != -1)
                    {
                        modelHis.CreatTime = DateTime.Now;

                        #region 会员历史信息
                        modelHis.OpenId = model.OpenId;
                        modelHis.Nickname = model.Nickname;
                        modelHis.Question1 = model.Question1;
                        modelHis.Question2 = model.Question2;
                        modelHis.Question3 = model.Question3;
                        modelHis.Anwser1 = model.Anwser1;
                        modelHis.Anwser2 = model.Anwser2;
                        modelHis.Anwser3 = model.Anwser3;
                        modelHis.Email = model.Email;
                        modelHis.Phone = model.Phone;
                        modelHis.LoginPWD = model.LoginPWD;
                        modelHis.Type = model.Type;
                        modelHis.Photo = model.Photo;
                        modelHis.PhotoURL = model.PhotoURL;
                        modelHis.Gender = model.Gender;
                        modelHis.Birthday = model.Birthday;
                        modelHis.Birthplace = model.Birthplace;
                        modelHis.Education = model.Education;
                        modelHis.Job = model.Job;
                        modelHis.Address = model.Address;
                        modelHis.LoginTimes = model.LoginTimes;
                        modelHis.LastLoginDateTime = model.LastLoginDateTime;
                        modelHis.CurrentLoginDateTime = model.CurrentLoginDateTime;
                        modelHis.Integral = model.Integral;
                        modelHis.Status = model.Status;
                        #endregion

                        MemberOP.SaveHistoryOfMemberUpdate(modelHis);
                        isSuccess = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Msg = ex.Message;
                isSuccess = false;
            }
            return isSuccess;
        }