Пример #1
0
        public async Task <IActionResult> ConfirmPost(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("Not Found", "User with the following email doesnt exist");
                }

                var result = await(_userManager as CognitoUserManager <CognitoUser>).ConfirmSignUpAsync(user, model.Code, true);
                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(error.Code, error.Description);
                    }
                    return(View(model));
                }
            }
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Confirm_Post(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "Es wurde kein Benutzer mit diesre email gefunden");
                    return(View(model));
                }
                var result = await((CognitoUserManager <CognitoUser>)_userManager)
                             .ConfirmSignUpAsync(user, model.Code, true);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                    return(View(model));
                }
            }
            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("UserNotFound", "User with given email is not found");
                    return(View(model));
                }

                var result = await _userManager.ConfirmSignUpAsync(user, model.Code, false);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(error.Code, error.Description);
                    }
                    return(View(model));
                }
            }
            return(View(model));
        }
Пример #4
0
        public async Task <IActionResult> Confirm_Post(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);

                if (User == null)
                {
                    ModelState.AddModelError("not found", "user emailwa s not found");
                }

                var result = await(_userManager as CognitoUserManager <CognitoUser>).ConfirmSignUpAsync(user, model.Code, true).ConfigureAwait(false);
                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                }
            }
            return(View(model));
        }
Пример #5
0
        public async Task <APIResponse> Confirm([FromBody] ConfirmModel model)
        {
            // validate
            if (BaseValidableModel.IsInvalid(model, out var errFields))
            {
                return(APIResponse.BadRequest(errFields));
            }

            var user       = (DAL.Models.Identity.User)null;
            var agent      = GetUserAgentInfo();
            var userLocale = GetUserLocale();

            // check token
            if (!await JWT.IsValid(
                    appConfig: AppConfig,
                    jwtToken: model.Token,
                    expectedAudience: JwtAudience.Cabinet,
                    expectedArea: Common.JwtArea.Registration,
                    validStamp: async(jwt, id) => {
                user = await UserManager.FindByNameAsync(id);
                return("");
            }
                    ) || user == null)
            {
                return(APIResponse.BadRequest(nameof(model.Token), "Invalid token"));
            }

            if (!user.EmailConfirmed)
            {
                user.EmailConfirmed = true;
                await DbContext.SaveChangesAsync();
            }
            return(APIResponse.Success());
        }
Пример #6
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userPool.FindByIdAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("User Not Found", "A user with the given address was not found");
                return(View(model));
            }

            var userManager = _userManager as CognitoUserManager <CognitoUser>;

            var result = await userManager.ConfirmSignUpAsync(user, model.Code, true);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.Code, error.Description);
                }

                return(View(model));
            }

            return(RedirectToAction(controllerName: "Home", actionName: "Index"));
        }
Пример #7
0
 public ActionResult Confirm(ConfirmModel model)
 {
     if (!Manager.IsAuthentication)
     {
         throw new HttpException(401, "Вы не авторизованы");
     }
     else if (!Manager.User.Login.Equals(model.Login))
     {
         throw new HttpException(423, "Ошибка доступа");
     }
     else if (!Manager.User.ActivationCode.Equals(model.Code))
     {
         ModelState.AddModelError("", "Коды не совпадают");
         return(View(model));
     }
     else if (!ModelState.IsValid)
     {
         return(View(model));
     }
     else
     {
         Manager.SetActiveCode(Manager.User);
         return(Redirect(Url.Action("Index", "Home")));
     }
 }
Пример #8
0
        public async Task ConfirmAsync(ConfirmModel model)
        {
            using (var client = new AmazonDynamoDBClient(RegionEndpoint.APSouth1))
            {
                using (var context = new DynamoDBContext(client))
                {
                    var record = await context.LoadAsync <DBModel>(model.Id);

                    if (record == null)
                    {
                        throw new KeyNotFoundException($"A record with ID={model.Id} was not found.");
                    }
                    if (model.Status == ImageUploaderStatus.Active)
                    {
                        record.FilePath = model.FilePath;
                        record.Status   = ImageUploaderStatus.Active;
                        await context.SaveAsync(record);
                    }
                    else
                    {
                        await context.DeleteAsync(record);
                    }
                }
            }
        }
Пример #9
0
        public async Task <IActionResult> ConfirmSend(ConfirmModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Confirm", model));
            }

            var user = await userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("NotFound", "A user with given email was not found");
                return(View("Confirm", model));
            }

            await signInManager.SignInAsync(user, true);

            var result = await userManager.ConfirmSignUpAsync(user, model.Code, false);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index", "Home"));
            }

            foreach (var item in result.Errors)
            {
                ModelState.AddModelError(item.Code, item.Description);
            }



            return(View("Confirm", model));
        }
Пример #10
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.EMail);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "A user with the given email is not found");
                    return(View(model));
                }

                var cognitoUserManager = (CognitoUserManager <CognitoUser>)_userManager;

                var result = await cognitoUserManager.ConfirmSignUpAsync(user, model.Code, true)
                             .ConfigureAwait(false);

                if (result.Succeeded)

                {
                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var e in result.Errors)
                {
                    ModelState.AddModelError(e.Code, e.Description);
                }
            }
            return(View(model));
        }
Пример #11
0
        public async Task <IActionResult> Confirm_Post(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "User with this email was not found");
                    return(View(model));
                }

                // var result =await _userManager.ConfirmEmailAsync(user, model.Code);//the third parameter is solve the nullReference issue
                var result = await((CognitoUserManager <CognitoUser>)_userManager).ConfirmSignUpAsync(user, model.Code, true);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                    return(View(model));
                }
            }

            return(View(model));
            //return null;
        }
        public async Task <ActionResult> ConfirmSignup(ConfirmModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                return(NotFound());
            }
            var result = await((CognitoUserManager <CognitoUser>)_userManager).ConfirmSignUpAsync(user, model.Code, true);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.Code, item.Description);
                }
            }
            return(View(model));
        }
Пример #13
0
        public static Task AlertUser(string title, string message)
        {
            var dataContext = new ConfirmModel
			{
				Title = title,
				Message = message,
                AllowCancel = false,
			};
			var inputWindow = new ConfirmWindow()
			{
				DataContext = dataContext
			};

			var tcs = new TaskCompletionSource<bool>();

			inputWindow.Closed += (sender, args) =>
			{
				if (inputWindow.DialogResult == true)
					tcs.SetResult(true);
				else
					tcs.SetCanceled();
			};

			inputWindow.Show();

			return tcs.Task;
        }
Пример #14
0
		public static Task<bool> ConfirmationAsync(string title, string question)
		{
			var dataContext = new ConfirmModel
			{
				Title = title,
				Message = question
			};
			var inputWindow = new ConfirmWindow
			{
				DataContext = dataContext
			};

			var tcs = new TaskCompletionSource<bool>();

			inputWindow.Closed += (sender, args) =>
			{
				if (inputWindow.DialogResult != null)
					tcs.SetResult(inputWindow.DialogResult.Value);
				else
					tcs.SetCanceled();
			};

			inputWindow.Show();

			return tcs.Task;
		}
Пример #15
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Invalid", "Email or code is not valid!");
                return(View(model));
            }
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("Invalid", "Email or code is not valid!");
                return(View(model));
            }
            var result = await((CognitoUserManager <CognitoUser>)_userManager).ConfirmSignUpAsync(user, model.Code, true);

            if (result.Succeeded)
            {
                return(RedirectToAction("Dashboard"));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.Code, item.Description);
                }
            }
            return(View(model));
        }
Пример #16
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "Brugerens email findes ikke");
                    return(View(model));
                }

                var result = await _userManager.ConfirmEmailAsync(user, model.Code);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                    return(View(model));
                }
            }
            return(View());
        }
Пример #17
0
 public async Task <IActionResult> Confirm(ConfirmModel model)
 {
     if (ModelState.IsValid)
     {
         var user = _userManager.FindByEmailAsync(model.Email).Result;
         if (user.Status == null)
         {
             ModelState.AddModelError("NotFound", "A user with the given email address was not found.");
             return(View(model));
         }
         var result = await(_userManager as CognitoUserManager <CognitoUser>).ConfirmSignUpAsync(user, model.Code, false).ConfigureAwait(false);
         if (result.Succeeded)
         {
             return(RedirectToAction("index", "home"));
         }
         else
         {
             foreach (var err in result.Errors)
             {
                 ModelState.AddModelError(err.Code, err.Description);
             }
             return(View(model));
         }
     }
     return(View(model));
 }
Пример #18
0
        // GET: Computer/Confirm
        public ActionResult Confirm()
        {
            ConfirmModel model  = new ConfirmModel();
            string       action = Request.Cookies["action"].Value;

            if (action == "loan")
            {
                ViewBag.DropdownMessage  = "Vælg en computer";
                ViewBag.DropdownButton   = "Udlån";
                model.AvailableComputers = DbDataAccess.GetData <SelectComputerModel>("GetAvailableComputers", null).Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
            }
            else if (action == "return")
            {
                ViewBag.DropdownMessage = "Indlever din PC";
                ViewBag.DropdownButtong = "Aflever";
                Dapper.DynamicParameters parameters = new Dapper.DynamicParameters();
                parameters.Add("@username", Request.Cookies["username"].Value);
                model.AvailableComputers = DbDataAccess.GetData <SelectComputerModel>("GetLentComputer", parameters).Select(s => new SelectListItem {
                    Value = s.Id.ToString(), Text = s.Name
                }).ToList();
            }
            return(View(model));
        }
Пример #19
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("InvalidData", "Please check input values.");
                return(View(model));
            }

            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("NotFound", "User with the given email address is not found.");
                return(View(model));
            }

            var result = await _userManager.ConfirmSignUpAsync(user, model.Code, true);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.Code, item.Description);
                }

                return(View(model));
            }
        }
Пример #20
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);

                if (user == null || user.Status == null)
                {
                    ModelState.AddModelError("UserNotExists", "Invalid Confirmation");
                }
                else
                {
                    var confirmResult = await(_userManager as CognitoUserManager <CognitoUser>).ConfirmSignUpAsync(user, model.Code, true).ConfigureAwait(false);

                    if (confirmResult.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        foreach (var error in confirmResult.Errors)
                        {
                            ModelState.AddModelError(error.Code, error.Description);
                        }
                    }
                }
            }

            return(View(model));
        }
Пример #21
0
        public async Task <IActionResult> ConfirmPost(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "A user with given email address was not found");
                    return(View(model));
                }

                var result = await _userManager.ConfirmEmailAsync(user, model.Code);

                if (result.Succeeded)
                {
                    return(RedirectToAction(actionName: "Index", controllerName: "Home"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(error.Code, error.Description);
                    }
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "User is not found");
                }

                var cognitoUserManager = _userManager as CognitoUserManager <CognitoUser>;
                var result             = await cognitoUserManager.ConfirmSignUpAsync(user, model.Code, true);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    result.Errors.ToList().ForEach(e => ModelState.AddModelError(e.Code, e.Description));
                }
            }
            return(View(model));
        }
Пример #23
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "User with this Email not found.");
                    return(View(model));
                }

                var result = await((CognitoUserManager <CognitoUser>)_userManager).ConfirmSignUpAsync(user, model.Code, true);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var identityError in result.Errors)
                    {
                        ModelState.AddModelError(identityError.Code, identityError.Description);
                    }

                    return(View(model));
                }
            }

            return(View(model));
        }
Пример #24
0
        public async Task <IActionResult> ConfirmPost(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                CognitoUser user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "A user with the given email address was not found");
                    return(View(model));
                }

                IdentityResult result = await((CognitoUserManager <CognitoUser>)_userManager).ConfirmSignUpAsync(user, model.Code, true).ConfigureAwait(false);
                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else //ModelState.AddModelError("ConfirmPost", string.Join<string>(" - ", result.Errors.Select(error => error.Description).ToList()));
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                }

                return(View(model));
            }

            return(View(model));
        }
Пример #25
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                // fetch the user by userManager
                var user = await this._userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "A user with the email address not found");
                    return(View(model));
                }

                var result = await((CognitoUserManager <CognitoUser>) this._userManager).ConfirmSignUpAsync(user, model.Code, true).ConfigureAwait(false);
                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }

                    return(View(ModelState));
                }
            }

            return(View());
        }
Пример #26
0
        public async Task <IActionResult> Signup(SignUpModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _pool.GetUser(model.Email);

                // we have name attribute required. At the moment, we dont have a name passed in, so we can use the email temporarily.
                // user will not be null even if it does not exist.
                user.Attributes.Add("name", model.Email);

                // without second parameter, a new user is created with password autogenerated.
                // if is user exists, it will fail here.
                var createResult = await _userManager.CreateAsync(user, model.Password);

                if (createResult.Succeeded)
                {
                    var confirmModel = new ConfirmModel
                    {
                        Email = model.Email,
                        Code  = string.Empty
                    };

                    return(RedirectToAction("Confirm", confirmModel));
                }

                foreach (var item in createResult.Errors)
                {
                    ModelState.AddModelError(item.Code, item.Description);
                }
            }

            return(View(model));
        }
Пример #27
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                AddUserNotFoundModelState();
                return(View(model));
            }

            try
            {
                await user.ConfirmSignUpAsync(model.Code, true);

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("SignUpError", $"Failed to Confirm SignUp. Error: {e.Message}");
                return(View(model));
            }
        }
Пример #28
0
        public async Task <IActionResult> Confirm_Post(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "User with given email address not found.");
                    return(View(model));
                }

                var result = await _userManager.ConfirmEmailAsync(user, model.Code).ConfigureAwait(false);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                }
            }

            return(View(model));
        }
Пример #29
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userMnManager.FindByEmailAsync(model.Email);

                if (user.Status == null)
                {
                    ModelState.AddModelError("UserNotFound", "unable to locate user");
                    return(View(model));
                }
                else
                {
                    var result = await(_userMnManager as CognitoUserManager <CognitoUser>).ConfirmSignUpAsync(user, model.Code, true);
                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        foreach (var item in result.Errors)
                        {
                            ModelState.AddModelError(item.Code, item.Description);
                        }

                        return(View(model));
                    }
                }
            }

            return(View(model));
        }
Пример #30
0
        public async Task <IActionResult> ConfirmPost(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);

                if (user == null)
                {
                    ModelState.AddModelError("ConfirmError", "Email address not found.");
                    return(View(model));
                }

                var result = await((CognitoUserManager <CognitoUser>)_userManager)
                             .ConfirmSignUpAsync(user, model.Code, true).ConfigureAwait(false);

                if (!result.Succeeded)
                {
                    ModelState.AddModelError("ConfirmError", "Unable to confirm account.");
                    return(View(model));
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
Пример #31
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "A user with the given email address was not found");
                    return(View(model));
                }

                //var result = await _userManager.ConfirmEmailAsync(user, model.Code);
                var result = await(_userManager as CognitoUserManager <CognitoUser>).ConfirmSignUpAsync(user, model.Code, true);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }

                    return(View(model));
                }
            }

            return(View(model));
        }
Пример #32
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("User not found", "User with this email not found");
                    return(View(model));
                }

                var confirm = await((CognitoUserManager <CognitoUser>)_userManager).ConfirmSignUpAsync(user, model.Code, true);
                if (confirm.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var error in confirm.Errors)
                {
                    ModelState.AddModelError(error.Code, error.Description);
                }
            }

            return(View());
        }