예제 #1
0
        public string savePassword([FromBody] changePassword data)
        {
            擺腹BuyFoodContext dbcontext    = new 擺腹BuyFoodContext();
            TMember          reviseTarget = dbcontext.TMembers.FirstOrDefault(n => n.CMemberId == int.Parse(data.memberID));

            ShareFunction sf           = new ShareFunction();
            SHA1          sha1         = SHA1.Create();
            string        SHAoPassword = sf.GetHash(sha1, data.oPassword);
            //string SHAoPassword = data.oPassword;
            string SHAnPassword = sf.GetHash(sha1, data.nPassword);

            if (SHAoPassword != reviseTarget.CPassword)
            {
                return("1");
            }
            reviseTarget.CPassword = SHAnPassword;
            dbcontext.SaveChanges();
            return("0");
        }
예제 #2
0
        public JsonResult loginCheck([FromBody] CLoginViewModel loginMember)
        {
            擺腹BuyFoodContext db = new 擺腹BuyFoodContext();
            var check信箱         = from n in db.TMembers
                                  select n.CEmail;

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

                var check密碼 = (from n in db.TMembers
                               where n.CEmail == loginMember.CEmail
                               select n).FirstOrDefault();

                SHA1 sha1 = SHA1.Create();

                string pwd解密 = shareFun.GetHash(sha1, loginMember.CPassword);

                if (check密碼.CFreezeCount >= 4)
                {
                    return(Json("memberFrozed"));
                }
                else if (check密碼.CPassword == pwd解密)
                {
                    if (check密碼.COpenMember == 0)
                    {
                        return(Json("notOpen"));
                    }
                    else
                    {
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERNAME, check密碼.CName);
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERPHOTO, check密碼.CPicture);
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERID, check密碼.CMemberId.ToString());

                        freezeCheck.CFreezeCount = 0;
                        db.SaveChanges();

                        return(Json("loginSuccess"));
                    }
                }
                else
                {
                    if (check密碼.CFreezeCount == 3)
                    {
                        freezeCheck.CFreezeCount += 1;
                        db.SaveChanges();
                        return(Json("FrozeComplete"));
                    }
                    else
                    {
                        freezeCheck.CFreezeCount += 1;
                        db.SaveChanges();
                        return(Json("FrozeCountPlus"));
                    }
                }
            }
            else
            {
                return(Json("noEmail"));
            }
        }
예제 #3
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));
            }
        }