public CustomPrincipal(UserModel user, UserData uData) { this.User = user; UserData = uData; if (User != null) Identity = new GenericIdentity(user.Id.ToString()); }
public async Task<ActionResult> LogOn(LogOnViewModel model, string returnUrl) { try { if (ModelState.IsValid) { var resp = await _accountService.Authenticate(model.Login.Trim(), model.Password.Trim()); if (!string.IsNullOrEmpty(resp?.access_token)) { var userData = new UserData() {AuthTicket = resp}; Response.SetAuthCookie(model.Login, false, userData); //var usersService = new UsersService(resp.access_token, new JsonSerializer()); //await usersService.AddUser(new UserModel() //{ // Username = "******", // Roles = new []{"Student"}, // PersonalDetail = new PersonalDetailModel() // { // Email = "stud1", // FirstName = "StudentFN", // LastName = "StudentLN" // } //}); return RedirectToLocal(returnUrl); } else ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect."); } else ModelState.AddModelError(string.Empty, "Invalid input"); model.Password = string.Empty; return View(model); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.ToString()); model.Password = string.Empty; return View(model); } }