public async Task <IActionResult> SendCredentials(string userEmail) { try { var user = await _userManager.FindByEmailAsync(userEmail); if (user == null) { throw new Exception("User does not exist!"); } var model = new UserCredentialViewModel { Email = userEmail }; return(View(model)); } catch (Exception e) { return(View("Error", new ErrorViewModel { RequestId = e.Message })); } }
public async Task <IActionResult> SendEmail(string userEmail) { try { var user = await _userManager.FindByEmailAsync(userEmail); if (user == null) { throw new Exception("User cannot be found!"); } var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.ResetPasswordCallbackLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailAsync(userEmail, "CRM Credentials", "Your email is: " + userEmail + $"\nPlease create your password by clicking here: <a href='{callbackUrl}'>link</a>"); var viewModel = new UserCredentialViewModel { Email = "" }; return(View("SendCredentials", viewModel)); } catch (Exception e) { return(View("Error", new ErrorViewModel { RequestId = e.Message })); } }
/// <summary> /// Update the user credentials. /// </summary> /// <param name="userCredentialView">credential for a user.</param> /// <returns></returns> public Response <UserCredentialViewModel> UpdateUserCredential(UserCredentialViewModel userCredentialView) { var apiUrl = baseRoute + "UpdateUserCredential"; var response = communicationManager.Post <UserCredentialModel, Response <UserCredentialModel> >(userCredentialView.ToModel(), apiUrl); return(response.ToModel()); }
public virtual ActionResult ValidateCredentials(UserCredentialViewModel viewmodel) { return(new ServiceAction(this) .Fetch(SessionKey.Empty) .WithResult <LoggedUserInfoDto>(() => { var loggedUserInfo = _userService.Authenticate(viewmodel.Username, viewmodel.Password); Session.SetValue(SessionKey.LoggedUser, loggedUserInfo); return loggedUserInfo; }) .Execute()); }
public async Task <IActionResult> SignIn(UserCredentialViewModel userCredentialViewModel) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index")); } if (!ModelState.IsValid) { return(RedirectToAction("Login", "Home")); } var response = await AdminHttpClient.PostAsync(WebConfiguration.Instance.WebApiConfig, "api/Auth/Login", userCredentialViewModel, Request); if (!response.IsSuccessStatusCode) { return(RedirectToAction("Login", "Home", "", "LoginFail")); } var credential = await response.Content.ReadAsAsync <UserCredentialViewModel>(); CookieOptions cookieOptions = new CookieOptions { Path = "/", Expires = DateTime.Now.AddHours(5), SameSite = SameSiteMode.Strict, IsEssential = true }; var val = credential.Token; Response.Cookies.Append(ConfigKeys.AuthCookieKey, val, cookieOptions); var model = await AdminHttpClient.GetAsync <RegistrationModelView>(WebConfiguration.Instance.WebApiConfig, $"api/Registration/{userCredentialViewModel.UserName}/token", credential.Token); if (model != null) { val = HttpUtility.UrlEncode(JsonConvert.SerializeObject( new { FullName = model.FirstLastName, model.Email, model.Id, model.MobileNumber }, Formatting.None)); Response.Cookies.Append(ConfigKeys.UserCookieKey, val, cookieOptions); } return(RedirectToAction("Index", "Home")); }
public async Task <UserCredentialViewModel> GetAssetCredentials(string selectedAsset) { var asset = await _assetRepository.FindOne(x => x.Key == selectedAsset); if (asset == null) { return(null); } var credentials = await( from credential in _credentialRepository.DbSet.Where(c => c.AssetName == asset.Key).OrderByDescending(s => s.HackerName) from credentialValue in _credentialValueRepository.DbSet.Where(cv => cv.AssetName == credential.AssetName && cv.Key == credential.Key) select new { Credential = credential, CredentialValue = credentialValue } ).ToListAsync(); var userCredentialViewModel = new UserCredentialViewModel { AssetName = asset.Key, Description = asset.Description, Columns = asset.Columns.Split(",").ToList(), Credentials = new List <CredentialsViewModel>(), }; foreach (var credentialEntity in credentials.GroupBy(c => c.Credential)) { var credentialsViewModel = new CredentialsViewModel { Rows = new Dictionary <int, List <(string ColumnName, string ColumnValue)> >(), HackerName = credentialEntity.Key.HackerName, Transferred = credentialEntity.Key.Transferred }; foreach (var row in credentialEntity.Select(x => x.CredentialValue)) { if (!credentialsViewModel.Rows.ContainsKey(row.RowNumber)) { credentialsViewModel.Rows.Add(row.RowNumber, new List <(string ColumnName, string ColumnValue)>()); } credentialsViewModel.Rows[row.RowNumber].Add((row.ColumnName, row.ColumnValue)); } userCredentialViewModel.Credentials.Add(credentialsViewModel); } return(userCredentialViewModel); }
public ActionResult DoAuthenticate(UserCredentialViewModel userCredential) { ViewBag.Message = "Welcome User!"; /* * Making our first request to validated user credential * 1) On success we get the security-token * 2) Place the security token in cookie so that it could be used on subsequent request which ever requires it for authentication */ var result = securityClient.Login(userCredential.UserName, userCredential.Password); if (result.LoginSuccess) { Response.Cookies.Add(new HttpCookie("STKN", result.SecurityToken)); } else { ViewBag.Message = "Login failed!"; } return(View("Index")); }
public static UserCredentialViewModel ToModel(this UserCredentialModel entity) { if (entity == null) { return(null); } var model = new UserCredentialViewModel { UserCredentialID = entity.UserCredentialID, UserID = entity.UserID, CredentialID = entity.CredentialID, Name = entity.CredentialName, Description = entity.Description, LicenseRequired = entity.LicenseRequired, LicenseNbr = entity.LicenseNbr, LicenseIssueDate = entity.LicenseIssueDate, LicenseExpirationDate = entity.LicenseExpirationDate, ModifiedOn = entity.ModifiedOn }; return(model); }
public JsonResult UpdateUserCredential(UserCredentialViewModel userCredentialView) { return(Json(adminRepository.UpdateUserCredential(userCredentialView), JsonRequestBehavior.AllowGet)); }