public async Task <IActionResult> VerifyCode(User userViewModel) { if (ModelState.IsValid) { var getCode = _context.Users.Where(U => U.SecurityStamp == userViewModel.SecurityStamp).Any(); if (!getCode) { return(BadRequest(new { msg = "Verification proccess is failed. Please enter the valid code" })); } var userEmail = _context.UserRoles.Include("Role").Include("User").Where(U => U.User.Email == userViewModel.Email).FirstOrDefault(); var getBiodata = _context.Employees.Where(Q => Q.Id == userEmail.User.Id).FirstOrDefault(); var getUser = new VerifyViewModel(); userEmail.User.SecurityStamp = null; userEmail.User.EmailConfirmed = true; getUser.RoleName = userEmail.Role.Name; getUser.Username = userEmail.User.UserName; getUser.Id = userEmail.User.Id; getUser.Email = userEmail.User.Email; getUser.Phone = userEmail.User.PhoneNumber; getUser.Adddress = getBiodata.Address; getUser.Gender = getBiodata.Gender; getUser.FullName = getBiodata.FullName; await _context.SaveChangesAsync(); return(StatusCode(200, getUser)); } return(BadRequest(500)); }
public IHttpActionResult Verify(VerifyViewModel input) { try { var mediator = new TextCheckMediator(new TextCheckMediatorModel() { Text = input.BarName, WordTree = (WordTree)HttpContext.Current.Application["WordTree"] }); var result = mediator.Process(); if (result.HttpStatusCode != HttpStatusCode.NoContent) { return(Content(result.HttpStatusCode, result)); } return(StatusCode(HttpStatusCode.NoContent)); } catch (Exception ex) { Logger.Log(ex); return(Content(HttpStatusCode.InternalServerError, new ResultDTO() { HttpStatusCode = HttpStatusCode.InternalServerError, Message = ex.Message })); } }
public CustomJsonResult Verify(VerifyViewModel model) { CustomJsonResult reuslt = new CustomJsonResult(); reuslt = BizFactory.OrderToTalentDemand.Verify(this.CurrentUserId, model.Operate, model.OrderToTalentDemand, model.BizProcessesAudit); return(reuslt); }
public void VerifyViewModel_CanExecute_True() { VerifyViewModel Validate = new VerifyViewModel(Datalist); bool Expected = true; bool Result = Validate.SubmitCommand.CanExecute(true); Assert.AreEqual(Result, Expected); }
public async Task RegistrationController_VerifyEmail_GET_Success() { //ARRANGE: //1.Arrange the test setup variables var user = new User { UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = null }; var organisation = new Core.Entities.Organisation { OrganisationId = 1 }; var userOrganisation = new UserOrganisation { OrganisationId = organisation.OrganisationId, Organisation = organisation, UserId = 1, PINConfirmedDate = VirtualDateTime.Now, PIN = "0" }; //Set user email address verified code and expired sent date var routeData = new RouteData(); routeData.Values.Add("Action", "VerifyEmail"); routeData.Values.Add("Controller", "Registration"); //ARRANGE: //1.Arrange the test setup variables var model = new VerifyViewModel(); model.EmailAddress = "*****@*****.**"; model.Resend = false; //Set model as if email // model.Sent = true; model.UserId = 1; // model.WrongCode = false; //var controller = UiTestHelper.GetController<RegistrationController>(); var controller = UiTestHelper.GetController <RegistrationController>(1, routeData, user /*, userOrganisation*/); controller.Bind(model); //ACT: //2.Run and get the result of the test var result = await controller.VerifyEmail(model) as ViewResult; //ASSERT: Assert.NotNull(result, "Expected ViewResult"); Assert.That(result.GetType() == typeof(ViewResult), "Incorrect resultType returned"); Assert.That(result.ViewName == "VerifyEmail", "Incorrect view returned,Verification is incomplete"); Assert.That( result.Model != null && result.Model.GetType() == typeof(VerifyViewModel), "Expected VerifyViewModel or Incorrect resultType returned"); Assert.That(result.ViewData.ModelState.IsValid, "Model is Invalid"); }
public IActionResult Login(UserViewModel userVM) { if (ModelState.IsValid) { var pwd = userVM.Password; var masuk = _context.UserRoles.Include("Role").Include("User").FirstOrDefault(m => m.User.Email == userVM.Email); if (masuk == null) { return(BadRequest("Please use the existing email or register first")); } else if (!BCrypt.Net.BCrypt.Verify(userVM.Password, masuk.User.PasswordHash)) { return(BadRequest("Incorret password")); } else if (pwd == null || pwd.Equals("")) { return(BadRequest("Please enter the password")); } else { var getBiodata = _context.Employees.Where(Q => Q.Id == masuk.User.Id).FirstOrDefault(); var user = new VerifyViewModel(); user.Id = masuk.User.Id; user.Username = masuk.User.UserName; user.Email = masuk.User.Email; user.Phone = masuk.User.PhoneNumber; user.RoleName = masuk.Role.Name; user.Adddress = getBiodata.Address; user.Gender = getBiodata.Gender; user.FullName = getBiodata.FullName; if (user.Username != null) { var Claims = new List <Claim> { new Claim(JwtRegisteredClaimNames.Sub, _configuration["Jwt:Subject"]), new Claim("id", user.Id), new Claim("uname", user.Username), new Claim("email", user.Email), new Claim("phone", user.Phone), new Claim("RoleName", user.RoleName), new Claim("address", user.Adddress), new Claim("gender", user.Gender), new Claim("fullName", user.FullName) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:Key"])); var signIn = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_configuration["Jwt:Issuer"], _configuration["Jwt:Audience"], Claims, notBefore: DateTime.UtcNow, expires: DateTime.UtcNow.AddDays(1), signingCredentials: signIn); return(Ok(new JwtSecurityTokenHandler().WriteToken(token))); } return(StatusCode(200, user)); } } return(BadRequest(500)); }
public async Task <IActionResult> Verify([FromQuery] string code, [FromQuery] Guid userId) { var hasVerificationCode = await httpHandler.CheckCodeAndUserIfExists(code, userId); var vm = new VerifyViewModel { CodeExists = hasVerificationCode, Code = code }; return(View(vm)); }
public IActionResult Verify(VerifyViewModel model) { var user = this._context.Users.FirstOrDefault(u => u.EmailAddress.ToLower() == model.EmailAddress.ToLower() && u.RegistrationCode == model.RegistrationCode); if (user != null) { user.LoginStatus = Infrastructures.Enums.LoginStatus.Active; user.LoginTrials = 0; this._context.Users.Update(user); this._context.SaveChanges(); return(RedirectToAction("login")); } return(View()); }
public async Task <IActionResult> SetPassword(NewPasswordViewModel model) { if (ModelState.IsValid) { await httpHandler.SetPassword(model.Password, model.Code); return(Redirect("/Account/Login")); } var vm = new VerifyViewModel() { CodeExists = true, InvalidPassword = true }; return(View("Verify", vm)); }
public async Task <IActionResult> ActiveAccount(VerifyViewModel model, string returnUrl = null) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); var result = new IdentityResult(); switch (model.VerifyType) { case "Email": result = await _userManager.ConfirmEmailAsync(user, model.Code); break; case "SMS": result = await _userManager.ChangePhoneNumberAsync(user, user.PhoneNumber, model.Code); break; default: break; } if (result.Succeeded) { user.IsActive = true; await _userManager.UpdateAsync(user); await _signInManager.SignInAsync(user, isPersistent : false); if (String.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("Index", "Company")); } return(RedirectToLocal(returnUrl)); } else if (user.IsActive == true) { ModelState.AddModelError("Code", _localizer.GetLocalizedHtmlString("activated")); } else { ModelState.AddModelError("Code", _localizer.GetLocalizedHtmlString("invalidActivation")); } } return(View(model)); }
public async Task <IActionResult> ConfirmIdentity(VerifyViewModel model) { string message = null; try { if (!ModelState.IsValid) { message = "تکمیل همه موارد ستاره دار الزامی میباشد"; return(RedirectToAction("Register", new { msg = message })); } if (model != null) { var newUser = await _userManager.FindByNameAsync(model.UserName); if (newUser != null) { TokenGenerator tokenGenerator = new TokenGenerator(_userManager, _db); int result = await tokenGenerator.ApproveVerificationToken(newUser, model.Token); if (result == 1) { message = "ثبت نام شما با موفقیت انجام پذیرفت"; return(RedirectToAction("Index", "Home", new { msg = message })); } else if (result == 0) { message = "کد وارد شده صحیح نمیباشد، جهت تایید در صفحه ثبت نام، گزینه ارسال مجدد کد تایید را انتخاب نمایید "; return(RedirectToAction("Register", new { msg = message })); } else if (result == -2) { message = "اعتبار کد تایید وارد شده به پایان رسیده، از گزینه ارسال مجدد کد تایید استفاده نمایید"; return(RedirectToAction("Register", new { msg = message })); } } } message = "در مراجل ثبت نام شما مشکلی رخ داده است"; return(RedirectToAction("Register", new { msg = message })); } catch (Exception ex) { message = "در مراجل ثبت نام شما مشکلی رخ داده است."; return(RedirectToAction("Register", new { msg = message })); } }
public IActionResult Verify(VerifyViewModel model) { var user = this._context.Users.FirstOrDefault(u => u.RegistrationCode == model.RegistrationCode); if (user != null) { user.LoginStatus = Infrastructures.Domain.Enums.LoginStatus.Active; user.LoginRetries = 0; this._context.Users.Update(user); this._context.SaveChanges(); return(RedirectToAction("Welcome")); } return(View()); }
public async Task <IActionResult> VerifyEmail(VerifyViewModel model) { //Ensure user has completed the registration process var checkResult = await CheckUserRegisteredOkAsync(); if (checkResult != null) { return(checkResult); } //Reset the verification send date VirtualUser.EmailVerifySendDate = null; VirtualUser.EmailVerifyHash = null; await SharedBusinessLogic.DataRepository.SaveChangesAsync(); //Call GET action which will automatically resend return(await VerifyEmail()); }
public async Task RegistrationController_VerifyEmail_GET_RedirectResult_Success() //Registration complete { //ARRANGE: //1.Arrange the test setup variables var code = "abcdefg"; var user = new User { UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = null, EmailVerifySendDate = VirtualDateTime.Now, EmailVerifyHash = Crypto.GetSHA512Checksum(code) }; //Set the user up as if finished step1 which is email known etc but not sent var routeData = new RouteData(); routeData.Values.Add("Action", "VerifyEmail"); routeData.Values.Add("Controller", "Registration"); var model = new VerifyViewModel(); //var controller = UiTestHelper.GetController<RegistrationController>(); var controller = UiTestHelper.GetController <RegistrationController>(1, routeData, user); controller.AddMockQuerystringValue("code", code); //ACT: //2.Run and get the result of the test var result = await controller.VerifyEmail(code) as RedirectToActionResult; //ASSERT: Assert.NotNull(result, "Expected RedirectToActionResult"); //Check the user is return the confirmation view Assert.That(result.ActionName == "EmailConfirmed", "Email is has not been confirmed!"); //Check the user verification is now marked as sent Assert.NotNull(user.EmailVerifiedDate, "Email is has not been confirmed!"); //Check a verification has been set against user Assert.That(user.Status == UserStatuses.Active, "Email is has not been confirmed!"); }
public IActionResult Verify(VerifyViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Verification code is required!"); return(View(model)); } var user = this._context.Users.FirstOrDefault(u => u.RegistrationCode == model.RegistrationCode); if (user != null) { user.LoginStatus = Infrastructures.Domain.Enums.LoginStatus.Active; user.LoginRetries = 0; this._context.Users.Update(user); this._context.SaveChanges(); return(RedirectToAction("Welcome")); } return(View()); }
public async Task <bool> VerifyCertificateFile(VerifyViewModel model) { bool ret = false; byte[] datahash; try { datahash = null; var file = model.Files.FirstOrDefault(); if (file != null && file.Length > 0) { using (var stream = file.OpenReadStream()) { using (System.Security.Cryptography.HashAlgorithm sha256 = System.Security.Cryptography.SHA256.Create()) { datahash = sha256.ComputeHash(stream); } } var datahashString = Utils.Convert.ToHexString(datahash); HeaderModel header = SQLData.GetHeaderByData(datahashString); ret = (header != null) && (header.HeaderId == model.HeaderId); } } catch (Exception e) { ret = false; } return(ret); }
public async Task <IActionResult> Verify(VerifyInput verifyInput, CancellationToken cancellationToken) { VerifyResponse verifyResponse = await Payment.VerifyAsync(verifyInput.Token, cancellationToken); VerifyViewModel model = Mapper.Map <VerifyViewModel>(verifyResponse); model.Message = "عملیات انجام نشد"; if (verifyResponse.Status == "1" && verifyResponse.Message == "OK") { model.Message = "عملیات با موفقیت انجام شد "; CustomUser user; if (User.Identity.IsAuthenticated) { user = await UserManager.GetUserAsync(User); } else { user = await UserManager.GetByToken(verifyInput.Token, cancellationToken); } user.Transactions = new List <Transact> { new Transact { Balance = verifyResponse.Amount.ToDecimal(), Description = verifyResponse.Description, TransactType = TransactType.Creditor, TransactDate = DateTime.Now, CustomUserId = user.Id, TransactId = verifyResponse.TransId } }; user.PaymentToken = string.Empty; user.AccountBalance += verifyResponse.Amount.ToDecimal(); await UserManager.UpdateAsync(user); } return(View(model)); }
public IActionResult Verify(string id) { string str_id = HttpContext.Session.GetString("id"); Guid guid = new Guid(str_id); //call api to verify payment here........... //if successful save transref here. Booking booking = context.Bookings.Find(guid); booking.Payment_Ref = id; context.SaveChanges(); //View model for status view. VerifyViewModel verifyViewModel = new VerifyViewModel(); verifyViewModel.First_Name = booking.First_Name; verifyViewModel.Last_Name = booking.Last_Name; verifyViewModel.PhoneNumber = booking.PhoneNumber; verifyViewModel.Email = booking.Email; verifyViewModel.Address = booking.Address; verifyViewModel.Age = booking.Age; verifyViewModel.Payment_Ref = booking.Payment_Ref; verifyViewModel.Age = booking.Depature_Time; verifyViewModel.Fare = booking.Fare; verifyViewModel.From = booking.From; verifyViewModel.To = booking.To; verifyViewModel.Motor_park = booking.Motor_park; verifyViewModel.Prefered_Seat = booking.Prefered_Seat; verifyViewModel.Travel_Date = booking.Travel_Date; verifyViewModel.Depature_Time = booking.Depature_Time; verifyViewModel.Vehicle = booking.Vehicle; return(View(verifyViewModel)); }
public VerifyPage() { InitializeComponent(); BindingContext = new VerifyViewModel(); }
public async Task <IActionResult> VerifyEmail(string code = null) { //Ensure user has completed the registration process var checkResult = await CheckUserRegisteredOkAsync(); if (checkResult != null) { return(checkResult); } if (VirtualUser != null && !VirtualUser.EmailVerifiedDate.EqualsI(null, DateTime.MinValue)) { if (SharedBusinessLogic.AuthorisationBusinessLogic.IsAdministrator(VirtualUser)) { return(RedirectToAction("Home", "Admin")); } return(RedirectToAction("EmailConfirmed")); } //Make sure we are coming from EnterCalculations or the user is logged in var m = UnstashModel <SignUpViewModel>(); if (m == null && VirtualUser == null) { return(new ChallengeResult()); } var model = new VerifyViewModel { EmailAddress = VirtualUser.EmailAddress }; //If email not sent if (VirtualUser.EmailVerifySendDate.EqualsI(null, DateTime.MinValue)) { var verifyCode = await SendVerifyCodeAsync(VirtualUser); if (string.IsNullOrWhiteSpace(verifyCode)) { return(View("CustomError", WebService.ErrorViewModelFactory.Create(1004))); } ClearStash(); model.Sent = true; //If the email address is a test email then add to viewbag if (VirtualUser.EmailAddress.StartsWithI(SharedBusinessLogic.SharedOptions.TestPrefix) || SharedBusinessLogic.SharedOptions.ShowEmailVerifyLink) { ViewBag.VerifyCode = verifyCode; } //Tell them to verify email return(View("VerifyEmail", model)); } //If verification code has expired if (VirtualUser.EmailVerifySendDate.Value.AddHours(SharedBusinessLogic.SharedOptions .EmailVerificationExpiryHours) < VirtualDateTime.Now) { AddModelError(3016); model.Resend = true; //prompt user to click to request a new one this.CleanModelErrors <VerifyViewModel>(); return(View("VerifyEmail", model)); } var remainingLock = VirtualUser.VerifyAttemptDate == null ? TimeSpan.Zero : VirtualUser.VerifyAttemptDate.Value.AddMinutes(SharedBusinessLogic.SharedOptions.LockoutMinutes) - VirtualDateTime.Now; var remainingResend = VirtualUser.EmailVerifySendDate.Value.AddHours(SharedBusinessLogic.SharedOptions .EmailVerificationMinResendHours) - VirtualDateTime.Now; if (string.IsNullOrEmpty(code)) { if (remainingResend > TimeSpan.Zero) { //Prompt to check email or wait return(View("CustomError", WebService.ErrorViewModelFactory.Create(1102, new { remainingTime = remainingLock.ToFriendly(maxParts: 2) }))); } //Prompt to click resend model.Resend = true; return(View("VerifyEmail", model)); } //If too many wrong attempts if (VirtualUser.VerifyAttempts >= SharedBusinessLogic.SharedOptions.MaxEmailVerifyAttempts && remainingLock > TimeSpan.Zero) { return(View("CustomError", WebService.ErrorViewModelFactory.Create(1110, new { remainingTime = remainingLock.ToFriendly(maxParts: 2) }))); } ActionResult result; if (VirtualUser.EmailVerifyHash != Crypto.GetSHA512Checksum(code)) { VirtualUser.VerifyAttempts++; //If code min time has elapsed if (remainingResend <= TimeSpan.Zero) { model.Resend = true; AddModelError(3004); //Prompt user to request a new verification code this.CleanModelErrors <VerifyViewModel>(); result = View("VerifyEmail", model); } else if (VirtualUser.VerifyAttempts >= SharedBusinessLogic.SharedOptions.MaxEmailVerifyAttempts && remainingLock > TimeSpan.Zero) { return(View("CustomError", WebService.ErrorViewModelFactory.Create(1110, new { remainingTime = remainingLock.ToFriendly(maxParts: 2) }))); } else { result = View("CustomError", WebService.ErrorViewModelFactory.Create(1111)); } } else { //Set the user as verified VirtualUser.EmailVerifiedDate = VirtualDateTime.Now; //Mark the user as active VirtualUser.SetStatus(UserStatuses.Active, OriginalUser ?? VirtualUser, "Email verified"); //Get any saved fasttrack codes PendingFasttrackCodes = VirtualUser.GetSetting(UserSettingKeys.PendingFasttrackCodes); VirtualUser.SetSetting(UserSettingKeys.PendingFasttrackCodes, null); VirtualUser.VerifyAttempts = 0; //If not an administrator show confirmation action to choose next step result = RedirectToAction("EmailConfirmed"); } VirtualUser.VerifyAttemptDate = VirtualDateTime.Now; //Save the current user await SharedBusinessLogic.DataRepository.SaveChangesAsync(); //Prompt the user with confirmation return(result); }
public ViewResult Verify(int id) { VerifyViewModel model = new VerifyViewModel(id); return(View(model)); }
public IActionResult Validate(VerifyViewModel userVM) { if (userVM.Username == null) { var jsonUserVM = JsonConvert.SerializeObject(userVM); var buffer = System.Text.Encoding.UTF8.GetBytes(jsonUserVM); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var resTask = client.PostAsync("Accounts/login/", byteContent); resTask.Wait(); var result = resTask.Result; if (result.IsSuccessStatusCode) { var data = result.Content.ReadAsStringAsync().Result; if (data != "") { var handler = new JwtSecurityTokenHandler().ReadJwtToken(data); var account = new VerifyViewModel { Id = handler.Claims.Where(p => p.Type == "id").Select(s => s.Value).FirstOrDefault(), Username = handler.Claims.Where(p => p.Type == "uname").Select(s => s.Value).FirstOrDefault(), Email = handler.Claims.Where(p => p.Type == "email").Select(s => s.Value).FirstOrDefault(), Phone = handler.Claims.Where(p => p.Type == "phone").Select(s => s.Value).FirstOrDefault(), RoleName = handler.Claims.Where(p => p.Type == "RoleName").Select(s => s.Value).FirstOrDefault(), Adddress = handler.Claims.Where(p => p.Type == "address").Select(s => s.Value).FirstOrDefault(), Gender = handler.Claims.Where(p => p.Type == "gender").Select(s => s.Value).FirstOrDefault(), FullName = handler.Claims.Where(p => p.Type == "fullName").Select(s => s.Value).FirstOrDefault() }; if (account.RoleName == "Admin" || account.RoleName == "Sales" || account.RoleName == "HR") { HttpContext.Session.SetString("id", account.Id); HttpContext.Session.SetString("phone", account.Phone); HttpContext.Session.SetString("address", account.Adddress); HttpContext.Session.SetString("gender", account.Gender); HttpContext.Session.SetString("uname", account.Username); HttpContext.Session.SetString("email", account.Email); HttpContext.Session.SetString("lvl", account.RoleName); HttpContext.Session.SetString("fullName", account.FullName); HttpContext.Session.SetString("JWToken", "Bearer " + data); if (account.RoleName == "Admin") { return(Json(new { status = true, msg = "Login Successfully !" })); } else if (account.RoleName == "Sales") { return(Json(new { status = true, msg = "Login Successfully !" })); } else { return(Json(new { status = true, msg = "Login Successfully !" })); } } else { return(Json(new { status = false, msg = "Please registration first." })); } } else { return(Json(new { status = false, msg = "The data must be filled" })); } } else { return(Json(new { status = false, msg = "Something went wrong" })); } } return(Redirect("/login")); }
public void VerifyViewModel_True() { VerifyViewModel Validate = new VerifyViewModel(Datalist); Validate.SubmitCommand.Execute(null); }
public VerifyView(List <Jobs> list) { this.Datalist = list; InitializeComponent(); DataContext = new VerifyViewModel(Datalist); }