Ejemplo n.º 1
0
        public JsonResult MasterLogin(string username, string password, string wxToken = null)
        {
            bool wxLogin  = !string.IsNullOrWhiteSpace(wxToken);
            bool hasInput = !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password);

            if (!wxLogin && !hasInput)
            {
                return(ApiModel(message: "用户名和密码不能为空"));
            }

            Account    account  = null;
            C_UserInfo userInfo = null;

            if (wxLogin)
            {
                //微信授权登陆
                wxToken = HttpUtility.UrlDecode(wxToken);
                int userId;
                int.TryParse(DESEncryptTools.DESDecrypt(wxToken), out userId);
                userInfo = C_UserInfoBLL.SingleModel.GetModel(userId);
                account  = AccountBLL.SingleModel.GetAccountByUnionId(userInfo.UnionId);
            }

            string loginToken = string.Empty;
            string authToken  = string.Empty;

            if (account != null)
            {
                //登陆已绑定微信的账号
                authToken  = DESEncryptTools.DESEncrypt(account.Id.ToString());
                loginToken = Utils.BuildCookie(account.Id, account.UpdateTime);
            }
            else if (hasInput)
            {
                bool success = false;
                //用账号密码登录账号
                account = AccountBLL.SingleModel.LoginUserWhole(username, password);
                if (account == null)
                {
                    return(ApiModel(message: "用户名或密码错误"));
                }
                if (userInfo != null)
                {
                    account.UnionId = userInfo.UnionId;
                    success         = AccountBLL.SingleModel.Update(account, "UnionId");
                }
                if (userInfo != null && account != null && !success)
                {
                    return(ApiModel(message: "账号绑定微信失败"));
                }
                authToken  = DESEncryptTools.DESEncrypt(account.Id.ToString());
                loginToken = Utils.BuildCookie(account.Id, account.UpdateTime);
            }
            else
            {
                return(ApiModel(isok: true, message: "微信账号未绑定账号,请输入账号密码", data: "NewUser"));
            }

            return(ApiModel(isok: true, message: "登陆成功", data: new { loginToken, authToken }));
        }
Ejemplo n.º 2
0
        public ActionResult Index(int?appId = null, string username = null, string password = null, bool isKeep = false, string backurl = null)
        {
            if (!appId.HasValue)
            {
                result.msg = "参数不能为空_appId";
                return(Json(result));
            }

            //清除缓存
            CookieHelper.Remove("dz_UserCookieNew");
            Response.ContentEncoding = Encoding.UTF8;
            username = StringHelper.NoHtml(username.Trim());
            password = StringHelper.NoHtml(password);

            AuthRole admin = AuthRoleBLL.SingleModel.UserLogin(appId.Value, username, password);

            if (admin == null)
            {
                result.msg = "用户名或密码错误";
                return(Json(result));
            }

            XcxAppAccountRelation app = XcxAppAccountRelationBLL.SingleModel.GetModel(admin.AId);

            if (app == null)
            {
                result.msg = "小程序不存在";
                return(Json(result));
            }
            Account account = AccountBLL.SingleModel.GetModel(app.AccountId);

            if (account == null)
            {
                result.msg = "授权账号不存在";
                return(Json(result));
            }

            Session["userName"]    = username;
            Session["passWord"]    = password;
            Session["dzAccountId"] = account.Id.ToString();
            if (isKeep)//--保存本地用户名
            {
                CookieHelper.SetCookie("LoginUserName", HttpUtility.UrlEncode(username));
            }
            else
            {
                CookieHelper.Remove("LoginUserName");
            }

            Task.Factory.StartNew(() =>
            {
                AuthRoleBLL.SingleModel.UpdateLoginTime(admin);
            });

            result.code = 1;
            result.msg  = "登陆成功";
            result.obj  = new { loginToken = account.Id, authToken = DESEncryptTools.DESEncrypt(admin.Id.ToString()), url = $"/pin/main?Id={app.Id}&appId={app.Id}" };
            return(Json(result));
        }
Ejemplo n.º 3
0
 public string BuildCookie(Agentinfo agentinfo)
 {
     if (agentinfo == null)
     {
         return(string.Empty);
     }
     return(DESEncryptTools.DESEncrypt($@"{agentinfo.useraccountid}\r\n{agentinfo.updateitme.ToString("yyyy-MM-dd HH:mm:ss")}"));
 }
Ejemplo n.º 4
0
        public ActionResult WeChatLogin(string sessionGUID)
        {
            OAuthUserInfo oauthInfo = WxOAuth.SingleModel.GetOAuthInfo(sessionGUID);

            if (oauthInfo == null)
            {
                return(Content("错误"));
            }

            C_UserInfo userInfo   = C_UserInfoBLL.SingleModel.GetModelFromCache(oauthInfo.openid);
            C_UserInfo updateUser = new C_UserInfo
            {
                NickName   = oauthInfo.nickname,
                HeadImgUrl = oauthInfo.headimgurl,
                Address    = $"{oauthInfo.country}{oauthInfo.province}{oauthInfo.city}",
                OpenId     = oauthInfo.openid,
                UnionId    = oauthInfo.unionid,
                Sex        = oauthInfo.sex,
                Remark     = "公众号移动端授权用户",
                AddTime    = DateTime.Now,
                UpdateTime = DateTime.Now,
            };

            if (userInfo?.Id > 0)
            {
                C_UserInfoBLL.SingleModel.Update(updateUser, "NickName,HeadImgUrl,Address,Sex,UpdateTime");
                updateUser.Id = userInfo.Id;
            }
            else
            {
                int newId;
                if (!int.TryParse(C_UserInfoBLL.SingleModel.Add(updateUser)?.ToString(), out newId) || newId == 0)
                {
                    return(Content("保存用户信息失败"));
                }
                updateUser.Id = newId;
            }

            string  loginType = string.Empty;
            Account account   = AccountBLL.SingleModel.GetAccountByUnionId(updateUser.UnionId);

            if (!string.IsNullOrWhiteSpace(account?.Id.ToString()))
            {
                //已绑定小程序管理账号
                loginType = "master";
            }

            string loginToken = DESEncryptTools.DESEncrypt(updateUser.Id.ToString());

            return(Redirect($"/Shop/Admin#/?token={HttpUtility.UrlEncode(loginToken)}&type={loginType}"));
        }
Ejemplo n.º 5
0
        public JsonResult Login(string username, string password, string wxToken = null)
        {
            bool hasInput = !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password);
            //门店暂时不做微信登陆
            //bool wxLogin = !string.IsNullOrWhiteSpace(wxToken);

            //C_UserInfo userInfo = null;
            DishStore store = null;
            //if (!string.IsNullOrWhiteSpace(wxToken))
            //{
            //    int userId = 0;
            //    int.TryParse(DESEncryptTools.DESEncrypt(wxToken), out userId);
            //    userInfo = C_UserInfoBLL.SingleModel.GetModel(userId);
            //    DishStoreBLL.SingleModel.GetStoreByUserId(userInfo.Id);
            //}

            string loginToken = string.Empty;

            if (store != null)
            {
                loginToken = DESEncryptTools.Encrypt(store.id.ToString());
            }
            else if (hasInput)
            {
                store = DishStoreBLL.SingleModel.GetAdminByLoginParams(username, password);
                if (store == null)
                {
                    return(ApiModel(message: "用户名或密码错误"));
                }
                loginToken = DESEncryptTools.DESEncrypt(store.id.ToString());
            }
            else
            {
                return(ApiModel(message: "用户名和密码不能为空"));
            }

            return(ApiModel(isok: true, message: "登陆成功", data: new { loginToken, storeId = store.id }));
        }
Ejemplo n.º 6
0
        public ActionResult Reg(string act = "", string loginname = "", string password = "", string authCode = "", int aid = 0)
        {
            if (!string.IsNullOrEmpty(act))
            {
                if (aid <= 0 || loginname.Length == 0)
                {
                    result.msg = "非法请求";
                    return(Json(result));
                }
                if (act == "reg")
                {
                    PinStore store = PinStoreBLL.SingleModel.GetStoreByPhone(loginname);
                    if (store != null)
                    {
                        result.msg = "用户名已存在,请登陆";
                        return(Json(result));
                    }
                    string code = RedisUtil.Get <string>(loginname);
                    if (code == "" || authCode == "" || code != authCode)
                    {
                        result.msg = "验证码错误";
                        return(Json(result));
                    }
                    PinPlatform platform = PinPlatformBLL.SingleModel.GetModelByAid(aid);
                    store = new PinStore
                    {
                        aId       = aid,
                        rz        = 1,
                        state     = 1,
                        endDate   = DateTime.Now.AddDays(platform.freeDays),
                        loginName = loginname,
                        password  = Utility.DESEncryptTools.GetMd5Base32(password),
                        startDate = DateTime.Now,
                        userId    = 0,//
                        phone     = loginname,
                        logo      = "",
                        storeName = "",
                        agentId   = 0
                    };

                    object obj     = PinStoreBLL.SingleModel.Add(store);
                    int    storeId = 0;
                    if (!Convert.IsDBNull(obj))
                    {
                        storeId = Convert.ToInt32(obj);
                    }

                    if (storeId > 0)
                    {
                        //店铺开通成功,检查用户是否在小程序端授权过手机号码,如果有,进行关联
                        //拼享惠绑定的的appid为:
                        C_UserInfo userInfo = C_UserInfoBLL.SingleModel.GetModelByTelephone_appid(store.phone, "wxbb2fe3080d04c9b2");
                        if (userInfo != null)
                        {
                            userInfo.StoreId = storeId;
                            C_UserInfoBLL.SingleModel.Update(userInfo, "StoreId");
                        }

                        result.code = 1;
                        result.obj  = new
                        {
                            store.aId,
                            storeId = store.id,
                        };
                        result.msg = DESEncryptTools.DESEncrypt(store.id.ToString());
                    }
                    else
                    {
                        result.msg = "开通失败";
                        result.obj = 0;
                    }
                    return(Json(result));
                }
            }
            return(View());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 发送修改密码邮件
        /// </summary>
        /// <param name="AccountID">帐号ID</param>
        /// <param name="LoginId">登录ID(登录名)</param>
        /// <param name="Email">注册Email</param>
        /// <param name="Url">修改密码地址</param>
        /// <param name="SendEmail">发送人邮箱</param>
        /// <param name="SmtpUserNamme">发送人邮箱用户名</param>
        /// <param name="SmtpPassword">发送人邮箱密码</param>
        /// <param name="EmailHost">邮件服务器</param>
        /// <returns>是否发送成功</returns>
        public string GetPass_SendEmail(string AccountID, string LoginId, string Email, string Url, string SendEmail, string SmtpUserNamme, string SmtpPassword, string EmailHost)
        {
            try
            {
                SendMail SendMail = new SendMail();
                SendMail.Host          = EmailHost;                       //邮件服务器
                SendMail.SmtpUsername  = SmtpUserNamme;                   //发送人邮箱用户名
                SendMail.SendEmail     = SendEmail;                       //发送人邮箱
                SendMail.SmtpPassword  = SmtpPassword;                    //发送人邮箱密码
                SendMail.Port          = 25;                              //服务器端口
                SendMail.ReplyToEmail  = Email;                           //回复人邮箱帐号
                SendMail.ReplyUserName = LoginId;                         //回复人用户名
                SendMail.GetEmail      = Email;                           //收件人邮箱帐号


                #region  输参数

                Random random       = new Random();
                int    RandomValue1 = random.Next(1, 10000);
                int    RandomValue2 = random.Next(1, 10000);

                string X1 = DESEncryptTools.DESEncrypt(RandomValue1.ToString());     //干扰参数
                string X2 = DESEncryptTools.DESEncrypt(AccountID);                   //帐号ID
                string X3 = DESEncryptTools.DESEncrypt(LoginId);                     //登录ID
                string X4 = DESEncryptTools.DESEncrypt(RandomValue2.ToString());     //干扰参数
                string X5 = DESEncryptTools.DESEncrypt(DateTime.Now.ToString());     //过期时间

                //邮件标题
                SendMail.Title = "亲爱的" + LoginId + ":您的密码找回通知";

                #endregion
                // 邮件内容
                StringBuilder sb = new StringBuilder();
                sb.Append("<br/><b>亲爱的" + LoginId + ":</b><br>&nbsp;&nbsp;&nbsp;&nbsp;您好!<br/>&nbsp;&nbsp;&nbsp;&nbsp;点击如下链接地址修改密码:<br>");
                sb.Append("<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href='" + Url + "/Help/GetPassUrl.aspx?X1=" + X1 + "&X2=" + X2 + "&X3=" + X3 + "&X4=" + X4 + "&X5=" + X5 + "' target='_blank' title='点击链接进行修改'>");
                sb.Append(Url + "/Help/GetPassUrl.aspx?X1=" + X1 + "&X2=" + X2 + "&X3=" + X3 + "&X4=" + X4 + "&X5=" + X5 + "</a><br/>");
                sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>如果点击打不开,请将网址复制后输入浏览地址栏进行操作!</font><br><br>&nbsp;&nbsp;&nbsp;&nbsp;<b>本链接地址24小时内有效</b>");
                SendMail.Content = sb.ToString();

                //发送邮件
                if (SendMail.Send())
                {
                    //返回处理结果
                    string result = "";
                    switch (Email.Substring(Email.LastIndexOf("@") + 1, Email.LastIndexOf(".") - Email.LastIndexOf("@") - 1).ToLower())
                    {
                    case "sina":
                        result = "http://mail.sina.com.cn/";
                        break;

                    case "163":
                        result = "http://email.163.com/";
                        break;

                    case "qq":
                        result = "https://mail.qq.com/cgi-bin/loginpage";
                        break;

                    case "sohu":
                        result = "http://mail.sohu.com/";
                        break;

                    default:
                        break;
                    }
                    return(result);
                }
                else
                {
                    return("false");
                }
            }
            catch { return("false"); }
        }
Ejemplo n.º 8
0
        public ActionResult Login(int?appId = null, string username = null, string password = null, bool isKeep = false, string backurl = null)
        {
            if (!appId.HasValue)
            {
                result.msg = "参数不能为空_appId";
                return(Json(result));
            }

            //清除缓存
            Response.ContentEncoding = Encoding.UTF8;
            username = StringHelper.NoHtml(username.Trim());
            password = StringHelper.NoHtml(password);

            AuthRole admin = AuthRoleBLL.SingleModel.UserLogin(appId.Value, username, password);

            if (admin == null)
            {
                result.msg = "用户名或密码错误";
                return(Json(result));
            }

            XcxAppAccountRelationBLL appBLL = XcxAppAccountRelationBLL.SingleModel;
            XcxAppAccountRelation    app    = appBLL.GetModel(admin.AId);

            if (app == null)
            {
                result.msg = "小程序不存在";
                return(Json(result));
            }
            Account account = AccountBLL.SingleModel.GetModel(app.AccountId);

            if (account == null)
            {
                result.msg = "授权账号不存在";
                return(Json(result));
            }

            Session["userName"]    = username;
            Session["passWord"]    = password;
            Session["dzAccountId"] = account.Id.ToString();
            if (isKeep)//--保存本地用户名
            {
                CookieHelper.SetCookie("LoginUserName", HttpUtility.UrlEncode(username));
            }
            else
            {
                CookieHelper.Remove("LoginUserName");
            }

            Task.Factory.StartNew(() =>
            {
                AuthRoleBLL.SingleModel.UpdateLoginTime(admin);
            });

            int pageType = appBLL.GetXcxTemplateType(app.Id);
            Dictionary <int, string> getUrl = new Dictionary <int, string> {
                { (int)TmpType.拼享惠, $"/pin/main?Id={app.Id}&appId={app.Id}" },
                { (int)TmpType.小程序专业模板, $"/SubAccount/Welcome?appId={app.Id}&pagetype={pageType}" },
                { (int)TmpType.小未平台, $"/Plat/admin/Index?Id={appId}&appId={appId}" }
            };

            string url = getUrl[pageType];

            string loginToken = Utils.BuildCookie(account.Id, account.UpdateTime); //customer.useraccountid;
            string authToken  = DESEncryptTools.DESEncrypt(admin.Id.ToString());

            result.code = 1;
            result.msg  = "登陆成功";
            result.obj  = new { loginToken, authToken, url };
            return(Json(result));
        }
Ejemplo n.º 9
0
        public JsonResult Test(string accountId)
        {
            Account account = AccountBLL.SingleModel.GetModel(Guid.Parse(accountId));

            return(ApiModel(message: Utils.BuildCookie(account.Id, account.UpdateTime), code: DESEncryptTools.DESEncrypt(account.Id.ToString())));
        }
Ejemplo n.º 10
0
        public JsonResult GetShopAuth(Account account, DishStore store)
        {
            string loginToken = DESEncryptTools.DESEncrypt(store.id.ToString());

            return(ApiModel(isok: true, message: "获取授权Token成功", data: new { loginToken }));
        }
Ejemplo n.º 11
0
 public static string BuildCookie(Guid id, DateTime updateTime)
 {
     return(DESEncryptTools.DESEncrypt($@"{id.ToString()}\r\n{updateTime.ToString("yyyy-MM-dd HH:mm:ss")}"));
 }