Ejemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> RegisterLIVE(RegisterLiveViewModel model)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            GameAJaxDto ajd = new GameAJaxDto();

            var user = new ApplicationUser {
                UserName = model.Name, Email = model.Email, Name = model.Name, RegistrationDate = DateTime.Now
            };
            var result = await UserManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // 傳送包含此連結的電子郵件
                //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                //await UserManager.SendEmailAsync(user.Id, "熊i猜Email驗證信", "請按此連結確認您的帳戶 <a href=\"" + callbackUrl + "\">驗證</a>");
                await new AccountModel().RegisterFinsh(user);
                new UserRepository().addlive(user.Id);

                //寄送驗證信件

                /*string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                 * var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                 * string emailBody = EmailTemplatesService.GetVerifyEmailHTML(callbackUrl);
                 * await UserManager.SendEmailAsync(user.Id, "熊i猜Email驗證信", emailBody);*/



                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            //AddErrors(result);

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            //ajd.isTrue = false;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        //直播擴充程式
        public async Task <JsonResult> LoginExtensions(LoginViewModel model, string returnUrl)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            GameAJaxDto ajd = new GameAJaxDto();
            // 這不會計算為帳戶鎖定的登入失敗
            // 若要啟用密碼失敗來觸發帳戶鎖定,請變更為 shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Name, model.Password, model.RememberMe, shouldLockout : false);

            // string[] array = new string[2];
            switch (result)
            {
            case SignInStatus.Success:
                //Session["Assets"] = new AssetsRepository().getAssetsListByUserID(User.Identity.GetUserId());
                var live = new UserRepository().getlive();


                var user = UserManager.FindByName(model.Name);
                if (live.Count == 0)
                {
                    //ModelState.AddModelError("", "登入嘗試失試。");
                    ajd.isTrue   = false;
                    ajd.ErrorMsg = "Liveerror";
                    return(Json(ajd, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    if (live.Where(x => x.username == user.Id).FirstOrDefault() == null)
                    {
                        ajd.isTrue   = false;
                        ajd.ErrorMsg = "Liveerror";
                        return(Json(ajd, JsonRequestBehavior.AllowGet));
                    }
                }



                GamePosts         gamepost = new GamePostsRepository().getLive(user.Id);
                GamePostViewModel gpvm     = new GamePostViewModel();
                gpvm.gamepost = gamepost;

                ajd.gpvm = gpvm;

                //Session["levelExp"] = new AssetsRepository().getExpByUserID(User.Identity.GetUserId());

                ajd.userId   = user.Id;
                ajd.username = user.UserName;
                ajd.isTrue   = true;
                ajd.live     = (int)live.Where(x => x.username == user.Id).FirstOrDefault().valid;
                return(Json(ajd, JsonRequestBehavior.AllowGet));

            //return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
            //return View("Lockout");
            case SignInStatus.RequiresVerification:
            //return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "登入嘗試失試。");
                ajd.ErrorMsg = "error";
                ajd.isTrue   = false;
                // array[0] = "error";
                return(Json(ajd, JsonRequestBehavior.AllowGet));
            }
        }