Beispiel #1
0
        public JsonResult forgetMemberCheck([FromBody] CForgetPasswordViewModel forgetPwdMember)
        {
            擺腹BuyFoodContext db = new 擺腹BuyFoodContext();
            var check信箱         = from n in db.TMembers
                                  select n.CEmail;

            if (check信箱.Any(n => n == forgetPwdMember.CEmail) == true)
            {
                TMember checkPhone = (from n in db.TMembers
                                      where n.CEmail == forgetPwdMember.CEmail
                                      select n).FirstOrDefault();

                if (checkPhone.CPhone == forgetPwdMember.CPhone)
                {
                    SHA1   sha1           = SHA1.Create();
                    string RandomPwd      = shareFun.產生亂數(16);
                    string ReplacementPwd = shareFun.GetHash(sha1, RandomPwd);
                    checkPhone.CPassword = ReplacementPwd;
                    db.SaveChanges();

                    string val信件內容 = "您的密碼已被修改成 : " + RandomPwd + " , 請登入後自行修改密碼";

                    shareFun.sendGrid(checkPhone.CEmail, checkPhone.CName, "BuyFood帳號開通認證信", val信件內容);


                    return(Json("EditSuccess"));
                }
                else
                {
                    return(Json("wrongPhone"));
                }
            }
            else
            {
                return(Json("noEmail"));
            }
        }
Beispiel #2
0
        public JsonResult CreateNewMember([FromBody] CCustomerCreateViewModel newMember)
        {
            擺腹BuyFoodContext db = new 擺腹BuyFoodContext();

            var check信箱 = from n in db.TMembers
                          select n.CEmail;

            var check手機 = from n in db.TMembers
                          select n.CPhone;

            if (check信箱.Any(n => n == newMember.CEmail) == true)
            {
                return(Json("EmailRepeat"));
            }
            else if (check手機.Any(n => n == newMember.CPhone) == true)
            {
                return(Json("PhoneRepeat"));
            }
            else
            {
                string 邀請碼 = shareFun.產生亂數(6);


                newMember.CBlackList      = 0;
                newMember.CFreezeCount    = 0;
                newMember.CDeposit        = 0;
                newMember.CRegisteredTime = DateTime.Now;
                newMember.COpenMember     = 0;


                var check邀請碼 = from n in db.TMembers
                               select n.CReferrerCode;

                //抓推薦人
                if (!string.IsNullOrEmpty(newMember.code))
                {
                    var 抓推薦人 = from n in db.TMembers
                               where n.CReferrerCode == newMember.code
                               select n.CMemberId;

                    int[] 推薦人ID = 抓推薦人.ToArray();
                    newMember.CReferrerID = 推薦人ID[0];
                }
                else
                {
                    newMember.CReferrerID = null;
                }

                //防止邀請碼重複
                while (check邀請碼.Any(n => n == 邀請碼) == true)
                {
                    邀請碼 = shareFun.產生亂數(6);
                }

                newMember.CReferrerCode = 邀請碼;

                db.TMembers.Add(newMember.member);
                db.SaveChanges();

                //註冊折價卷
                var 新增註冊折價卷 = from n in db.TMembers
                              where n.CMemberId == newMember.CMemberID
                              select n.CReferrerId;

                int?[] 邀請人ID = 新增註冊折價卷.ToArray();


                if (邀請人ID[0] != null)
                {
                    TCupon 新增邀請人折價卷 = new TCupon
                    {
                        CCuponCategoryId = 2,
                        CMenberId        = (int)邀請人ID[0],
                        CBeUsed          = 0,
                        CDiscountCode    = shareFun.產生亂數(6),
                        CReceivedTime    = DateTime.Now,
                        CValidDate       = DateTime.Now.AddDays(60)
                    };
                    TCupon 新增新會員折價卷 = new TCupon
                    {
                        CCuponCategoryId = 3,
                        CMenberId        = newMember.CMemberID,
                        CBeUsed          = 0,
                        CDiscountCode    = shareFun.產生亂數(6),
                        CReceivedTime    = DateTime.Now,
                        CValidDate       = DateTime.Now.AddDays(60)
                    };
                    db.TCupons.Add(新增邀請人折價卷);
                    db.TCupons.Add(新增新會員折價卷);
                    db.SaveChanges();
                }

                //密碼雜湊
                TMember add密碼雜湊 = (from n in db.TMembers
                                   where n.CMemberId == newMember.CMemberID
                                   select n).FirstOrDefault();

                SHA1 sha1 = SHA1.Create();

                string 雜湊密碼 = shareFun.GetHash(sha1, add密碼雜湊.CPassword);

                add密碼雜湊.CPassword = 雜湊密碼;
                db.SaveChanges();

                string val信件內容 = "歡迎加入BuyFood,請點擊以下連結以開通帳號 \n" + CDictionary.LOCAL_WEBSITES + "/Customer/memberConfirm?ID=" + add密碼雜湊.CMemberId;

                shareFun.sendGrid(add密碼雜湊.CEmail, add密碼雜湊.CName, "BuyFood帳號開通認證信", val信件內容);

                return(Json(true));
            }
        }