Ejemplo n.º 1
0
        public async Task <IActionResult> Login(SignInViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await userManager.FindByNameAsync(model.UserName);

            if (user is null)
            {
                user = await userManager.FindByEmailAsync(model.UserName);

                if (user is null)
                {
                    ModelState.AddModelError(nameof(model.UserName), "نام کاربری اشتباه است");
                }
            }

            var IsPasswordValid = await userManager.CheckPasswordAsync(user, model.Password);

            if (!IsPasswordValid)
            {
                ModelState.AddModelError(nameof(model.Password), "رمز عبور اشتباه است");
            }

            if (ModelState.IsValid)
            {
                var myIp  = GetCurrentIpAddressExtention.Get(HttpContext);
                var token = await jwtService.GenerateAsync(user);

                var RefreshtokenGuid = await generateResreshTokenService.Generate(user, myIp);

                NameValueCollection datacollection = new NameValueCollection();
                datacollection.Add("token", token);
                datacollection.Add("refreshtoken", Convert.ToString(RefreshtokenGuid));
                var urlCallBack = decryptService.Decrypt(model.UCB);
                var form        = FormPostExtention.PreparePostForm(urlCallBack, datacollection);
                return(Content(form, "text/html"));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task GetJson()
        {
            try
            {
                var result = await _httpRequestService.GetJsonAsync();

                await _fileService.CreateFile(result);

                var decrypted = _decryptService.Decrypt(result);
                var hash      = _securityService.CreateHash(decrypted);

                await _fileService.UpdateFile(decrypted, hash);

                await _httpRequestService.PostAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
            Console.ReadKey();
        }