Beispiel #1
0
        public ActionResult QQRegister(Member member)
        {
            int qquserID = int.Parse(Request.Form["QQUserID"]);
            var result   = EnterRepository.GetRepositoryEnter().QQUserRepository.LoadEntities(m => m.ID == qquserID).FirstOrDefault();
            var item     = EnterRepository.GetRepositoryEnter().MemberRepository
                           .LoadEntities(m => m.UserName == member.UserName || m.Tel == member.Tel || m.Mail == member.Mail).FirstOrDefault();

            if (item != null)
            {
                return(Content("用户名、邮箱或手机号已存在"));
            }
            //创建会员信息
            member.CreateTime = DateTime.Now;
            member.Sex        = Request.Form["Gender"] == "男" ? 1 : 2;
            member.Password   = string.IsNullOrEmpty(member.Password)? Utility.MD5Helper.MD5(SystemContext.Instance.DefaultPwd): Utility.MD5Helper.MD5(member.Password);
            member.Picture    = result.Figureurl;
            EnterRepository.GetRepositoryEnter().MemberRepository.AddEntity(member);
            if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
            {
                return(Content("注册失败"));
            }
            //更新qquser的memberID

            result.MemberID = member.ID;
            EnterRepository.GetRepositoryEnter().QQUserRepository.Get(m => m.ID == qquserID);
            EnterRepository.GetRepositoryEnter().QQUserRepository.EditEntity(result, new string[] { "MemberID" });
            if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
            {
                return(Content("绑定失败"));
            }
            WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, "", member.Picture, 15);
            return(Content(""));
        }
Beispiel #2
0
        public ActionResult Update(Member member)
        {
            //验证用户名唯一
            var result = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.UserName == member.UserName && m.ID != member.ID).FirstOrDefault();

            if (result != null)
            {
                return(Content("已存在相同的用户名"));
            }
            //验证手机号唯一
            result = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.Tel == member.Tel && m.ID != member.ID).FirstOrDefault();
            if (result != null)
            {
                return(Content("手机号已注册"));
            }
            //验证邮箱唯一
            result = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.Mail == member.Mail && m.ID != member.ID).FirstOrDefault();
            if (result != null)
            {
                return(Content("邮箱已注册"));
            }
            EnterRepository.GetRepositoryEnter().MemberRepository.Get(m => m.ID == member.ID);
            EnterRepository.GetRepositoryEnter().MemberRepository.EditEntity(member, new string[] { "UserName", "RealName", "Sex", "Tel", "Mail", "QQ", "Age" });
            if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
            {
                return(Content("系统错误,修改失败"));
            }
            //放到cookie里
            WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, "", "", 15);
            return(Content(""));
        }
Beispiel #3
0
        public ActionResult Register(Member member)
        {
            //验证用户名唯一
            var result = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.UserName == member.UserName).FirstOrDefault();

            if (result != null)
            {
                return(Content("已存在相同的用户名"));
            }
            //验证手机号唯一
            result = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.Tel == member.Tel).FirstOrDefault();
            if (result != null)
            {
                return(Content("手机号已注册"));
            }
            //验证邮箱唯一
            result = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.Mail == member.Mail).FirstOrDefault();
            if (result != null)
            {
                return(Content("邮箱已注册"));
            }
            //密码MD5加密,默认密码为111111
            member.Password  = string.IsNullOrEmpty(member.Password) ? Utility.MD5Helper.MD5(SystemContext.Instance.DefaultPwd): Utility.MD5Helper.MD5(member.Password);
            member.Picture   = SystemContext.Instance.GetDefaultImg();
            member.LoginTime = DateTime.Now;
            EnterRepository.GetRepositoryEnter().MemberRepository.AddEntity(member);
            if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
            {
                return(Content("系统错误,注册失败"));
            }
            //放到cookie里
            WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, "", "", 15);
            return(Content(""));
        }
Beispiel #4
0
        public ActionResult QQConnect(QQUser qquser)
        {
            var result = EnterRepository.GetRepositoryEnter().QQUserRepository.LoadEntities(m => m.OpenID == qquser.OpenID).FirstOrDefault();

            if (result == null)
            {
                result            = new QQUser();
                result.OpenID     = qquser.OpenID;
                result.NickName   = qquser.NickName;
                result.Level      = qquser.Level;
                result.Gender     = qquser.Gender;
                result.Figureurl  = qquser.Figureurl;
                result.CreateTime = DateTime.Now;
                result.Vip        = qquser.Vip;
                EnterRepository.GetRepositoryEnter().QQUserRepository.AddEntity(result);
                EnterRepository.GetRepositoryEnter().SaveChange();
                return(Json(new
                {
                    msg = "注册",
                    ID = result.ID
                }));
            }
            if (result.MemberID == 0)
            {
                return(Json(new
                {
                    msg = "注册",
                    ID = result.ID
                }));
            }
            var member = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.ID == result.MemberID).FirstOrDefault();

            WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, "", member.Picture, 15);
            return(Content(""));
        }
Beispiel #5
0
        public ActionResult QQBind(Member member)
        {
            var result = EnterRepository.GetRepositoryEnter().MemberRepository
                         .LoadEntities(m => m.UserName == member.UserName || m.Tel == member.UserName || m.Mail == member.UserName).FirstOrDefault();

            if (result == null)
            {
                return(Content("用户名、邮箱或手机号不存在"));
            }
            if (result.Password != Utility.MD5Helper.MD5(member.Password))
            {
                return(Content("密码错误"));
            }
            int qquserID = int.Parse(Request.Form["QQUserID"]);

            //更新qquser的memberID
            var qquser = EnterRepository.GetRepositoryEnter().QQUserRepository.LoadEntities(m => m.ID == qquserID).FirstOrDefault();

            qquser.MemberID = result.ID;
            EnterRepository.GetRepositoryEnter().QQUserRepository.Get(m => m.ID == qquserID);
            EnterRepository.GetRepositoryEnter().QQUserRepository.EditEntity(qquser, new string[] { "MemberID" });
            if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
            {
                return(Content("绑定失败"));
            }
            WebCookieHelper.SetUserCookie(result.ID, result.UserName, result.Tel, "", "", 15);
            return(Content(""));
        }
Beispiel #6
0
 public ActionResult Telephone(FormCollection fc)
 {
     try
     {
         string id = WebCookieHelper.GetUserInfo(0);
         if (string.IsNullOrEmpty(id))
         {
             return(Redirect("/weixin/account/"));
         }
         int nid    = int.Parse(id);
         var result = EnterRepository.GetRepositoryEnter().OAuthUserRepository.LoadEntities(m => m.ID == nid).FirstOrDefault();
         if (result == null)
         {
             return(Redirect("/weixin/account/"));
         }
         result.Name = fc["Name"];
         result.Tel  = fc["Tel"];
         EnterRepository.GetRepositoryEnter().OAuthUserRepository.EditEntity(result, new string[] { "Name", "Tel" });
         if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
         {
             log.Info(string.Format("用户:{0}绑定手机号", result.NickName));
             WebCookieHelper.SetUserCookie(result.ID, result.Name, result.Tel, string.Empty, string.Empty, 7);
             return(Json(new { validate = "true", message = "绑定成功" }));
         }
         else
         {
             return(Json(new { validate = "false", message = "绑定失败" }));
         }
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return(Json(new { validate = "false", message = "绑定失败" }));
     }
 }
        public ActionResult Login(FormCollection form)
        {
            string name   = form["name"];
            string pwd    = form["pwd"];
            var    member = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.UserName == name ||
                                                                                               m.Tel == name || m.Mail == name).FirstOrDefault();

            if (member == null)
            {
                //从考试订房中获取考生资料
                var users = EnterRepository.GetRepositoryEnter().UsersRepository.LoadEntities(m => m.Tel == name).FirstOrDefault();
                if (users == null)
                {
                    return(Content("用户不存在"));
                }
                else
                {
                    //自动创建会员
                    member            = new Member();
                    member.CreateTime = DateTime.Now;
                    member.Tel        = users.Tel;
                    member.Picture    = SystemContext.Instance.GetDefaultImg();
                    member.Password   = Utility.MD5Helper.MD5(users.Pwd);
                    member.UserName   = users.Name + "_" + users.Sequences.ToString();
                    EnterRepository.GetRepositoryEnter().MemberRepository.AddEntity(member);
                    if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
                    {
                        return(Content("用户不存在"));
                    }
                    users.MemberID = member.ID;
                    EnterRepository.GetRepositoryEnter().UsersRepository.Get(m => m.ID == users.ID);
                    EnterRepository.GetRepositoryEnter().UsersRepository.EditEntity(users, new string[] { "MemberID" });
                    if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
                    {
                        return(Content("用户不存在"));
                    }
                }
            }
            else if (Utility.MD5Helper.MD5(pwd) != member.Password)
            {
                return(Content("密码错误"));
            }
            WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, "", member.Picture, 15);

            return(Content(string.Empty));
        }
Beispiel #8
0
        public ActionResult Login(FormCollection form)
        {
            string name   = form["name"];
            string pwd    = form["pwd"];
            var    member = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.UserName == name ||
                                                                                               m.Tel == name || m.Mail == name).FirstOrDefault();

            if (member == null)
            {
                //从考试订房中获取考生资料
                var users = EnterRepository.GetRepositoryEnter().UsersRepository.LoadEntities(m => m.Tel == name).FirstOrDefault();
                if (users == null)
                {
                    return(Content("用户不存在"));
                }
                else
                {
                    //自动创建会员
                    member            = new Member();
                    member.CreateTime = DateTime.Now;
                    member.Tel        = users.Tel;
                    member.Picture    = SystemContext.Instance.GetDefaultImg();
                    member.Password   = string.IsNullOrEmpty(users.Pwd)? Utility.MD5Helper.MD5(SystemContext.Instance.DefaultPwd): Utility.MD5Helper.MD5(member.Password);
                    member.UserName   = users.Name + "_" + users.Sequences.ToString();
                    EnterRepository.GetRepositoryEnter().MemberRepository.AddEntity(member);
                    if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
                    {
                        return(Content("用户不存在"));
                    }
                }
            }
            else if (Utility.MD5Helper.MD5(pwd) != member.Password)
            {
                return(Content("密码错误"));
            }
            WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, "", member.Picture, 15);
            string tel      = WebCookieHelper.GetUserInfo(2);
            var    employee = EnterRepository.GetRepositoryEnter().EmployeeRepository.LoadEntities(m => m.Tel == tel).FirstOrDefault();

            if (employee != null)
            {
                WebCookieHelper.SetEmployeeCookie(employee.ID, employee.Name, employee.EmpNo, employee.Tel, 15);
            }
            return(Content(string.Empty));
        }
Beispiel #9
0
        public ActionResult WeixinRegister(Member member)
        {
            var result = EnterRepository.GetRepositoryEnter().MemberRepository
                         .LoadEntities(m => m.Tel == member.Tel).FirstOrDefault();
            int oauthuserID = int.Parse(Request.Form["OAuthUserID"]);
            var oauthuser   = EnterRepository.GetRepositoryEnter().OAuthUserRepository.LoadEntities(m => m.ID == oauthuserID).FirstOrDefault();

            if (result == null)
            {
                //member不存在,创建member
                member.UserName   = oauthuser.NickName;
                member.CreateTime = DateTime.Now;
                member.Password   = Utility.MD5Helper.MD5(SystemContext.Instance.DefaultPwd);
                EnterRepository.GetRepositoryEnter().MemberRepository.AddEntity(member);
                if (EnterRepository.GetRepositoryEnter().SaveChange() < 0)
                {
                    return(Content("绑定失败"));
                }
                oauthuser.MemberID = member.ID;
            }
            else
            {
                oauthuser.MemberID = result.ID;
                member.UserName    = result.UserName;
            }

            //更新qquser的memberID
            EnterRepository.GetRepositoryEnter().OAuthUserRepository.Get(m => m.ID == oauthuserID);
            EnterRepository.GetRepositoryEnter().OAuthUserRepository.EditEntity(oauthuser, new string[] { "MemberID" });
            if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
            {
                return(Content("绑定失败"));
            }
            WebCookieHelper.SetUserCookie(oauthuser.MemberID, member.UserName, member.Tel, "", "", 15);
            return(Content(""));
        }
Beispiel #10
0
        /// <summary>
        /// OAuthScope.snsapi_userinfo方式回调
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public ActionResult UserInfoCallback(string code, string state)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Content("您拒绝了授权!"));
            }

            if (state != SystemContext.Instance.WeiXinAppInfo.Token)
            {
                //这里的state其实是会暴露给客户端的,验证能力很弱,这里只是演示一下
                //实际上可以存任何想传递的数据,比如用户ID,并且需要结合例如下面的Session["OAuthAccessToken"]进行验证
                return(Content("验证失败!请从正规途径进入!"));
            }

            OAuthAccessTokenResult result = null;

            //通过,用code换取access_token
            try
            {
                ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
                result = OAuthApi.GetAccessToken(SystemContext.Instance.WeiXinAppInfo.AppID, SystemContext.Instance.WeiXinAppInfo.AppSecret, code);
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
            if (result.errcode != ReturnCode.请求成功)
            {
                return(Content("错误:" + result.errmsg));
            }
            //下面2个数据也可以自己封装成一个类,储存在数据库中(建议结合缓存)
            //如果可以确保安全,可以将access_token存入用户的cookie中,每一个人的access_token是不一样的
            //Session["OAuthAccessTokenStartTime"] = DateTime.Now;
            //Session["OAuthAccessToken"] = result;

            //因为第一步选择的是OAuthScope.snsapi_userinfo,这里可以进一步获取用户详细信息
            try
            {
                ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
                OAuthUserInfo userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                //将用户资料保存进自己的库
                var oauthuser = EnterRepository.GetRepositoryEnter().OAuthUserRepository.LoadEntities(m => m.OpenID == userInfo.openid).FirstOrDefault();
                //微信公开信息记录数据库
                if (oauthuser == null)
                {
                    DateTime createTime = DateTime.Now;
                    string   pwd        = Utility.MD5Helper.MD5(SystemContext.Instance.DefaultPwd);
                    oauthuser = new Models.OAuthUser()
                    {
                        City = userInfo.city, Country = userInfo.country, Headimgurl = userInfo.headimgurl, NickName = userInfo.nickname, OpenID = userInfo.openid, Province = userInfo.province, Sex = userInfo.sex, CreateTime = createTime, Pwd = pwd
                    };

                    EnterRepository.GetRepositoryEnter().OAuthUserRepository.AddEntity(oauthuser);
                    if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
                    {
                        logger.Info("新增关注用户" + userInfo.nickname);
                    }
                }
                if (oauthuser.MemberID == 0)
                {
                    //绑定手机号,查找是否有相同号码的member,如果没有则创建member账号
                    return(Redirect("/member/weixinregister?ID=" + oauthuser.ID.ToString()));
                }
                var member = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.ID == oauthuser.MemberID).FirstOrDefault();
                if (member == null)
                {
                    GlobalMethod.log.Error("微信绑定的用户不存在了,重新绑定手机号");

                    //重新绑定手机号
                    return(Redirect("/member/weixinregister?ID=" + oauthuser.ID.ToString()));
                }
                WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, string.Empty, string.Empty, 7);
                if (Utility.CookieHelper.ExistCookie("returnurl"))
                {
                    return(Redirect(Utility.CookieHelper.GetCookie("returnurl")));
                }
                else
                {
                    return(Redirect("/member/personalinfo"));
                }
            }
            catch (ErrorJsonResultException ex)
            {
                logger.Error(ex);
                return(Content(ex.Message));
            }
        }