/// <summary> /// Called at the final stage of a successful Token endpoint request. An application may implement this call in order /// to do any final /// modification of the claims being used to issue access or refresh tokens. This call may also be used in order to add /// additional /// response parameters to the Token endpoint's json response body. /// </summary> /// <param name="context">The context of the event carries information in and results out.</param> /// <returns> /// Task to enable asynchronous execution /// </returns> public override async Task TokenEndpoint(OAuthTokenEndpointContext context) { var identityManager = new IdentityManager <TUser>(); var applicationUser = identityManager.ApplicationUserManager.FindByName(context.Identity.Name); await base.TokenEndpoint(context); if (applicationUser != null) { var user = new LoggedInUserInfo { FirstName = applicationUser.FirstName, LastName = applicationUser.LastName, EmailId = applicationUser.Email, Roles = identityManager.ApplicationUserManager.GetRoles(applicationUser.Id) }; var memoryStream = new MemoryStream(); var dataContractJsonSerializer = new DataContractJsonSerializer(typeof(LoggedInUserInfo)); dataContractJsonSerializer.WriteObject(memoryStream, user); memoryStream.Position = 0; context.AdditionalResponseParameters.Add("user", new StreamReader(memoryStream).ReadToEnd()); } }
public async Task <IActionResult> Login([FromBody] LoginViewModel info) { //info.userName = System.Net.WebUtility.UrlDecode(info.userName); //info.password = System.Net.WebUtility.UrlDecode(info.password); var user = await _userManager.FindByNameAsync(info.userName); if (user != null && await _userManager.CheckPasswordAsync(user, info.password)) { var roles = await _userManager.GetRolesAsync(user); LoggedInUserInfo userInfo = new LoggedInUserInfo(); userInfo.UserID = user.Id; userInfo.FirstName = user.FirstName; userInfo.LastName = user.LastName; userInfo.UserName = user.UserName; userInfo.Role = roles.FirstOrDefault(); var success = new SuccessfulLoginResponse { Token = Jwt.GetTokenFor(user.Id.ToString(), roles.FirstOrDefault()), User = userInfo }; var response = new LoginResponseViewModel(); response.successResonse = success; return(Ok(response)); } else { var response = new LoginResponseViewModel(); response.failedResponse = new FailedLoginResponse { Error = 1007 }; return(UnauthorizedError(response)); } }
public IActionResult Index() { TestViewModel model = new TestViewModel(); List <TestListViewModel> testList = new List <TestListViewModel>(); using (var repository = new WebApiClientRepository <List <TestListViewModel> >()) { int userID = 0; using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); userID = userInfo.UserID; } var payload = repository.GlobalApiCallGet(null, "api/Test/GetTestListByCoach?id=" + userID); if (payload != null) { testList = payload.ToList(); } } model.TestList = testList; var testTypeList = GetTestType(); ViewBag.TestTypeID = new SelectList(testTypeList, "ID", "Name"); return(View(model)); }
public ActionResult Create(TestViewModel model) { try { if (ModelState.IsValid) { PayloadResponse response = new PayloadResponse(); using (var repository = new WebApiClientRepository <PayloadResponse>()) { using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); model.CoachID = userInfo.UserID; } response = repository.GlobalApiCallPost(model, "api/Test/CreateTest"); if (response != null) { if (response.Success) { TempData["message_data_success"] = response.Message; return(RedirectToAction(nameof(Index))); } else { TempData["message_data"] = response.Message; return(RedirectToAction(nameof(Index))); } } else { TempData["message_data"] = "Problem on Test creation"; return(RedirectToAction(nameof(Index))); } } } else { TempData["message_data"] = "Problem on Test creation"; return(RedirectToAction(nameof(Index))); } } catch { TempData["message_data"] = "Problem on Test creation"; return(RedirectToAction(nameof(Index))); } }
private List <DropDownViewModel> GetAthlete() { List <DropDownViewModel> athleteList = new List <DropDownViewModel>(); using (var repository = new WebApiClientRepository <List <DropDownViewModel> >()) { int userID = 0; using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); userID = userInfo.UserID; } var payload = repository.GlobalApiCallGet(null, "api/Test/GetAllAthletesByCoachID?id=" + userID); if (payload != null) { athleteList = payload.ToList(); } } return(athleteList); }
public IActionResult Index() { AthleteTestViewModel model = new AthleteTestViewModel(); using (var repository = new WebApiClientRepository <AthleteTestViewModel>()) { int userID = 0; using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); userID = userInfo.UserID; } var payload = repository.GlobalApiCallGet(null, "api/Test/GetTestListByAthlete?id=" + userID); if (payload != null) { model = payload; return(View(model)); } } return(View(model)); }
private void UpdateSharedLoggedInUserInfo(ValidateUserLogin validateUserLogin) { Na.Core.SharedInfo _sharedInfo = new Na.Core.SharedInfo(); LoggedInUserInfo objLoggedInUserInfo = new LoggedInUserInfo(); objLoggedInUserInfo.FBUser = validateUserLogin.FBUser; objLoggedInUserInfo.LoginUserMiscInfo = validateUserLogin.LoginUserMiscInfo; objLoggedInUserInfo.User = validateUserLogin.User; objLoggedInUserInfo.UserAccount = validateUserLogin.UserAccount; _sharedInfo.LoggedInUserInfo = objLoggedInUserInfo; }
public IActionResult Index() { var token = string.Empty; var loggedInUserInfo = new LoggedInUserInfo(); using (var storage = new LocalStorage()) { if (storage.Exists("userInfo")) { loggedInUserInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); token = storage.Get("jwtToken").ToString(); } } if (string.IsNullOrEmpty(token)) { using (var storage = new LocalStorage()) { storage.Clear(); } return(View()); } PayloadResponse response = new PayloadResponse(); using (var repository = new WebApiClientRepository <PayloadResponse>()) { try { response = repository.GlobalApiCallPost(null, "api/Auth/KeepAlive"); if (response == null || !response.Success) { using (var storage = new LocalStorage()) { storage.Clear(); } return(View()); } } catch (Exception) { return(View()); } } if (loggedInUserInfo != null && loggedInUserInfo.UserID > 0) { switch (loggedInUserInfo.Role) { case "Coach": return(RedirectToAction(nameof(CoachController.Index), "Coach")); case "Athlete": return(RedirectToAction(nameof(AthleteController.Index), "Athlete")); default: ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View()); } } else { return(View()); } }