예제 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(_msgBox.ModelStateMsg(ModelState.GetErrors()));
            }


            var result = await _userApplication.LoginByUserNamePasswordAsync(Input.Email, Input.Password);

            if (result.IsSucceed)
            {
                // result.Message == userId
                string generatedToken = await _jwtBuilder.CreateTokenAync(result.Message);

                Response.CreateAuthCookie(generatedToken, Input.RemmeberMe);



                return(new JsResult("GotoReturnUrl()"));
            }
            else
            {
                return(_msgBox.InfoMsg(_localizer[result.Message]));
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(_msgBox.ModelStateMsg(ModelState.GetErrors()));
            }

            var result = await _userApplication.LoginByPhoneNumberStep2Async(Input.PhoneNumber, Input.Code);

            if (result.IsSucceed)
            {
                string generatedToken = await _jwtBuilder.CreateTokenAync(result.Message);

                Response.CreateAuthCookie(generatedToken, Input.RemmeberMe);

                return(new JsResult("GotoReturnUrl()"));
            }
            else
            {
                return(_msgBox.FaildMsg(_localizer[result.Message]));
            }
        }
예제 #3
0
        public async Task <IActionResult> OnGetAsync(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(StatusCode(400));
            }

            string decryptedToken = token.AesDecrypt(AuthConst.SecretKey);
            string userId         = decryptedToken.Split(", ")[0];
            string password       = decryptedToken.Split(", ")[1];
            string ip             = decryptedToken.Split(", ")[2];
            string date           = decryptedToken.Split(", ")[3];
            bool   remmeberMe     = bool.Parse(decryptedToken.Split(", ")[4]);

            var result = await _userApplication
                         .LoginByEmailLinkStep2Async(userId, password, ip,
                                                     HttpContext.Connection.RemoteIpAddress?.ToString(),
                                                     DateTime.Parse(date));

            if (result.IsSucceed)
            {
                string generatedToken = await _jwtBuilder.CreateTokenAync(result.Message);

                Response.CreateAuthCookie(generatedToken, remmeberMe);

                ViewData["Message"] = _localizer["LoginEmailSuccess"];
                ViewData["MsgType"] = "success";
                return(Page());
            }
            else
            {
                ViewData["Message"] = _localizer[result.Message];
                ViewData["MsgType"] = "danger";
                return(Page());
            }
        }