コード例 #1
0
        public ActionResult OauthCallBack(string oauthId)
        {
            Plugin <IOAuthPlugin> plugin          = PluginsManagement.GetPlugin <IOAuthPlugin>(oauthId);
            OAuthUserInfo         userInfo        = plugin.Biz.GetUserInfo(base.Request.QueryString);
            UserMemberInfo        memberByUnionId = null;

            if (!string.IsNullOrWhiteSpace(userInfo.UnionId))
            {
                memberByUnionId = ServiceHelper.Create <IMemberService>().GetMemberByUnionId(oauthId, userInfo.UnionId);
            }
            if (memberByUnionId == null && !string.IsNullOrWhiteSpace(userInfo.OpenId))
            {
                memberByUnionId = ServiceHelper.Create <IMemberService>().GetMemberByOpenId(oauthId, userInfo.OpenId);
            }
            if (memberByUnionId != null)
            {
                SellerLoginIn(memberByUnionId.UserName, memberByUnionId.Password, false);
                string str = UserCookieEncryptHelper.Encrypt(memberByUnionId.Id, "Web");
                WebHelper.SetCookie("ChemCloud-User", str.ToString());
                BizAfterLogin.Run(memberByUnionId.Id);
                return(Redirect("/"));
            }
            if (string.IsNullOrWhiteSpace(userInfo.OpenId))
            {
                return(View());
            }
            object[] objArray = new object[] { oauthId, userInfo.OpenId, userInfo.NickName, userInfo.UnionId, userInfo.OpenId };
            return(Redirect(string.Format("/Login/BindUser?oauthId={0}&openId={1}&name={2}&unionid={3}&unionopenid={4}", objArray)));
        }
コード例 #2
0
        /// <summary>
        /// 验证账户后,自动登录
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public ActionResult FromEmailVerification(string username, string password)
        {
            UserMemberInfo userMemberInfo = ServiceHelper.Create <IMemberService>().GetMemberByName(username);

            if (userMemberInfo.Disabled)
            {
                return(View(new UserMemberInfo()));
            }
            if (userMemberInfo != null && !string.IsNullOrEmpty(username) && userMemberInfo.Password == password && userMemberInfo.UserName == username)
            {
                userMemberInfo = ServiceHelper.Create <IMemberService>().GetMemberByName(username);
                if (userMemberInfo != null)
                {
                    userMemberInfo.Disabled = true;
                    ServiceHelper.Create <IMemberService>().UpdateMember(userMemberInfo);
                }
                if (userMemberInfo.UserType == 2)
                {
                    BizAfterLogin.Run(userMemberInfo.Id);
                    string str  = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "SellerAdmin");
                    string str1 = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "Web");

                    WebHelper.SetCookie("ChemCloud-SellerManager", str);
                    WebHelper.SetCookie("ChemCloud-User", str1);
                }
                else if (userMemberInfo.UserType == 3)
                {
                    BizAfterLogin.Run(userMemberInfo.Id);
                    string str = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "Web");
                    WebHelper.SetCookie("ChemCloud-User", str);
                }
            }
            return(View(userMemberInfo));
        }
コード例 #3
0
        public ActionResult OauthCallBack(string oauthId)
        {
            try
            {
                var oauthPlugin            = Core.PluginsManagement.GetPlugin <IOAuthPlugin>(oauthId);
                var oauthInfo              = oauthPlugin.Biz.GetUserInfo(Request.QueryString);
                Entities.MemberInfo member = null;
                if (oauthId.Equals("Himall.Plugin.OAuth.Weibo"))
                {
                    if (!string.IsNullOrEmpty(oauthInfo.OpenId))
                    {
                        //微博查询是否该OpenId对应的用户已经存在
                        member = _iMemberService.GetMemberByOpenId(oauthId, oauthInfo.OpenId);
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(oauthInfo.UnionId))//检查是否正确返回OpenId
                    {
                        //查询是否该UnionId对应的用户已经存在
                        member = _iMemberService.GetMemberByUnionId(oauthId, oauthInfo.UnionId);
                    }
                }
                if (member != null)
                {//存在,则直接登录
                    SellerLoginIn(member.UserName, member.Password);

                    base.SetUserLoginCookie(member.Id);
                    Application.MemberApplication.UpdateLastLoginDate(member.Id);

                    BizAfterLogin.Run(member.Id);//执行登录后初始化相关操作
                    return(Redirect("/"));
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(oauthInfo.OpenId))
                    {//扫码登录
                        string url = string.Format("/Login/BindUser?oauthId={0}&openId={1}&name={2}&unionid={3}&unionopenid={4}", oauthId, oauthInfo.OpenId, oauthInfo.NickName, oauthInfo.UnionId, oauthInfo.OpenId);
                        return(Redirect(url));
                    }
                }
                ViewBag.Keyword = SiteSettings.Keyword;
                return(View());
            }
            catch (Exception ex)//出异常(包括取消后回调,直接返回到登录页)
            {
                Log.Error(ex.ToString());
                return(Content(string.Format("<script type=\"text/javascript\">window.location.href = '{0}'; window.close();</script>", "/login")));
            }
        }
コード例 #4
0
ファイル: LoginController.cs プロジェクト: redpanda321/Mall
        public JsonResult Index(string username, string password)
        {
            try
            {
                //检查输入合法性
                CheckInput(username, password);

                var member = _iMemberService.Login(username, password);
                if (member == null)
                {
                    throw new LoginException("用户名和密码不匹配", LoginException.ErrorTypes.PasswordError);
                }

                if (PlatformType == Core.PlatformType.WeiXin)
                {
                    base.SetUserLoginCookie(member.Id);
                }
                else
                {
                    base.SetUserLoginCookie(member.Id, DateTime.MaxValue);
                }

                WebHelper.SetCookie(CookieKeysCollection.Mall_ACTIVELOGOUT, "0", DateTime.MaxValue);
                SellerLoginIn(username, password);
                BizAfterLogin.Run(member.Id);//执行登录后初始化相关操作
                return(Json(new { success = true, memberId = member.Id }));
            }
            catch (LoginException ex)
            {
                return(Json(new { success = false, msg = ex.Message }));
            }
            catch (MallException ex)
            {
                return(Json(new { success = false, msg = ex.Message }));
            }
            catch (Exception ex)
            {
                Core.Log.Error("用户" + username + "登录时发生异常", ex);
                return(Json(new { success = false, msg = "未知错误" }));
            }
        }
コード例 #5
0
        private Entities.MemberInfo UserLoginIn(string username, string password, bool keep = false)
        {
            var member = _iMemberService.Login(username, password);

            if (member == null)
            {
                throw new LoginException("用户名和密码不匹配", LoginException.ErrorTypes.PasswordError);
            }
            BizAfterLogin.Run(member.Id);

            if (keep)
            {
                base.SetUserLoginCookie(member.Id, DateTime.Now.AddDays(7));
            }
            else
            {
                base.SetUserLoginCookie(member.Id);
            }

            return(member);
        }
コード例 #6
0
ファイル: LoginController.cs プロジェクト: Shikyoh/HSWB2B2C
        private UserMemberInfo UserLoginIn(string username, string password, bool keep = false)
        {
            UserMemberInfo userMemberInfo = ServiceHelper.Create <IMemberService>().Login(username, password);

            if (userMemberInfo == null)
            {
                throw new LoginException("用户名和密码不匹配", LoginException.ErrorTypes.PasswordError);
            }
            BizAfterLogin.Run(userMemberInfo.Id);
            string str = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "Web");

            if (!keep)
            {
                WebHelper.SetCookie("Himall-User", str);
            }
            else
            {
                DateTime now = DateTime.Now;
                WebHelper.SetCookie("Himall-User", str, now.AddDays(7));
            }
            return(userMemberInfo);
        }
コード例 #7
0
ファイル: LoginController.cs プロジェクト: redpanda321/Mall
        public JsonResult BindUser(string username, string password, string headimgurl, string serviceProvider, string openId, Entities.MemberOpenIdInfo.AppIdTypeEnum appidtype = Entities.MemberOpenIdInfo.AppIdTypeEnum.Normal, string unionid = null, string sex = null, string city = null, string province = null, string country = null, string nickName = null)
        {
            var service = _iMemberService;
            var member  = service.Login(username, password);

            if (member == null)
            {
                throw new Mall.Core.MallException("用户名和密码不匹配");
            }

            //Log.Debug("BindUser unionid=" + (string.IsNullOrWhiteSpace(unionid) ? "null" : unionid));
            headimgurl = System.Web.HttpUtility.UrlDecode(headimgurl);
            nickName   = System.Web.HttpUtility.UrlDecode(nickName);
            city       = System.Web.HttpUtility.UrlDecode(city);
            province   = System.Web.HttpUtility.UrlDecode(province);
            OAuthUserModel model = new OAuthUserModel()
            {
                AppIdType     = appidtype,
                UserId        = member.Id,
                LoginProvider = serviceProvider,
                OpenId        = openId,
                Headimgurl    = headimgurl,
                UnionId       = unionid,
                Sex           = sex,
                NickName      = nickName,
                City          = city,
                Province      = province
            };

            service.BindMember(model);
            base.SetUserLoginCookie(member.Id);
            WebHelper.SetCookie(CookieKeysCollection.Mall_ACTIVELOGOUT, "0", DateTime.MaxValue);
            SellerLoginIn(username, password);
            BizAfterLogin.Run(member.Id);//执行登录后初始化相关操作

            return(Json(new { success = true }));
        }
コード例 #8
0
        public ActionResult OauthCallBack(string oauthId)
        {
            var            oauthPlugin = Core.PluginsManagement.GetPlugin <IOAuthPlugin>(oauthId);
            var            oauthInfo   = oauthPlugin.Biz.GetUserInfo(Request.QueryString);
            UserMemberInfo member      = null;

            if (!string.IsNullOrWhiteSpace(oauthInfo.UnionId))//检查是否正确返回OpenId
            {
                //查询是否该UnionId对应的用户已经存在
                member = _iMemberService.GetMemberByUnionId(oauthId, oauthInfo.UnionId);
            }
            //if (member == null && !string.IsNullOrWhiteSpace(oauthInfo.OpenId))
            //{
            //	//TODO:UnionId不存在,再验证openid
            //	member = _iMemberService.GetMemberByOpenId(oauthId, oauthInfo.OpenId);
            //}
            if (member != null)
            {//存在,则直接登录
                SellerLoginIn(member.UserName, member.Password);

                base.SetUserLoginCookie(member.Id);
                Application.MemberApplication.UpdateLastLoginDate(member.Id);

                BizAfterLogin.Run(member.Id);//执行登录后初始化相关操作
                return(Redirect("/"));
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(oauthInfo.OpenId))
                {//扫码登录
                    string url = string.Format("/Login/BindUser?oauthId={0}&openId={1}&name={2}&unionid={3}&unionopenid={4}", oauthId, oauthInfo.OpenId, oauthInfo.NickName, oauthInfo.UnionId, oauthInfo.OpenId);
                    return(Redirect(url));
                }
            }
            return(View());
        }
コード例 #9
0
        //private ManagerInfo SellerLoginIn(string username, string password, bool keep = false)
        //{
        //    ManagerInfo managerInfo = ServiceHelper.Create<IManagerService>().Login(username, password, false);
        //    if (managerInfo == null)
        //    {
        //        return null;
        //    }
        //    string str = UserCookieEncryptHelper.Encrypt(managerInfo.Id, "SellerAdmin");
        //    if (!keep)
        //    {
        //        WebHelper.SetCookie("ChemCloud-SellerManager", str);
        //    }
        //    else
        //    {
        //        DateTime now = DateTime.Now;
        //        WebHelper.SetCookie("ChemCloud-SellerManager", str, now.AddDays(7));
        //    }
        //    return managerInfo;
        //}

        /// <summary>
        /// 卖家和平台管理元登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="keep"></param>
        /// <returns></returns>
        private int SellerLoginIn(string username, string password, bool keep)
        {
            UserMemberInfo userMemberInfo = ServiceHelper.Create <IMemberService>().Login(username, password);

            if (userMemberInfo == null)
            {
                throw new LoginException("用户名和密码不匹配", LoginException.ErrorTypes.PasswordError);
            }

            if (userMemberInfo.UserType == 2)
            {
                if (userMemberInfo.Disabled == false)
                {
                    throw new LoginException("请到邮箱验证用户", LoginException.ErrorTypes.UsernameError);
                }
                BizAfterLogin.Run(userMemberInfo.Id);
                string str  = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "SellerAdmin");
                string str1 = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "Web");
                if (!keep)
                {
                    WebHelper.SetCookie("ChemCloud-SellerManager", str);
                    WebHelper.SetCookie("ChemCloud-User", str1);
                }
                else
                {
                    DateTime now = DateTime.Now;
                    WebHelper.SetCookie("ChemCloud-SellerManager", str, now.AddDays(7));
                    WebHelper.SetCookie("ChemCloud-User", str1, now.AddDays(7));
                }


                return(2);
            }
            else if (userMemberInfo.UserType == 3)
            {
                if (userMemberInfo.Disabled == false)
                {
                    throw new LoginException("用户未激活", LoginException.ErrorTypes.UsernameError);
                }
                BizAfterLogin.Run(userMemberInfo.Id);
                string str = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "Web");
                if (!keep)
                {
                    WebHelper.SetCookie("ChemCloud-User", str);
                }
                else
                {
                    DateTime now = DateTime.Now;
                    WebHelper.SetCookie("ChemCloud-User", str, now.AddDays(7));
                }
                if (userMemberInfo.ParentSellerId == 0)
                {
                    string            name     = "";
                    PurchaseRolesInfo roleInfo = ServiceHelper.Create <IPermissionGroupService>().GetPurchaseRoleByUserId(userMemberInfo.Id);
                    if (roleInfo == null)
                    {
                        long Languagetype = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Language"].ToString());
                        if (Languagetype == 1)
                        {
                            name = "管理员";
                        }
                        if (Languagetype == 2)
                        {
                            name = "Admin";
                        }
                        PurchaseRolesInfo roleInfos = ServiceHelper.Create <IPermissionGroupService>().AddPermissionGroup(userMemberInfo.Id, name);
                        if (roleInfos.Id != 0)
                        {//用户添加成功 添加组织结构
                            Organization oinfo = new Organization()
                            {
                                UserId       = userMemberInfo.Id,
                                RoleId       = roleInfos.Id,
                                RoleName     = roleInfos.RoleName,
                                ParentRoleId = 0,
                                ParentId     = 0
                            };
                            ServiceHelper.Create <IOrganizationService>().AddOrganization(oinfo);
                        }
                    }
                }
                return(3);
            }
            else
            {
                return(-1);
            }
        }