示例#1
0
		public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
		{
			ViewData["ReturnUrl"] = returnUrl;
			if (ModelState.IsValid)
			{
				var results = await signInManager.PasswordSignInAsync(model.Email, model.Password, false, false);
				if (results.Succeeded)
				{
					return RedirectToLocal(returnUrl);
				}
				else
				{
					ModelState.AddModelError(string.Empty, "Invalid login attempt.");
					return View(model);
				}
			}

			return View(model);
		}
示例#2
0
		public async Task<JsonResult> LoginFromDevice(LoginViewModel model)
		{
			if (ModelState.IsValid)
			{
				var results = await signInManager.PasswordSignInAsync(model.Email, model.Password, true, false);
				if (results.Succeeded)
				{
					var user = await userManager.FindByNameAsync(model.Email);
					return Json(new
					{
						Success = true,
						Name = user.Name
					});
				}
			}

			return Json(new
			{
				Success = false,
				Name = (String)null
			});
		}