Пример #1
0
 public async Task <IActionResult> DeleteCode(string id)
 {
     if (await codeService.DeleteCode(id))
     {
         return(View());
     }
     return(Redirect("/Administration/Code/AllCodes"));
 }
Пример #2
0
        public JsonResult Codes_Delete(IEnumerable <DeleteRequest> requests)
        {
            GeneralResponse response = new GeneralResponse();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("Code_Delete");
            if (!hasPermission)
            {
                ModelState.AddModelError("", "AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            #endregion

            response = _codeService.DeleteCode(requests);

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                if (MagicStrings.AdminEmails.Any(x => x == Input.Email.ToUpper()))
                {
                    var user = new ACMUser {
                        UserName = Input.Email, Email = Input.Email, FullName = Input.FullName, PhoneNumber = Input.PhoneNumber, AppartentNumber = int.Parse(Input.Code.Split("_")[0])
                    };
                    var result = await _userManager.CreateAsync(user, Input.Password);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created a new account with password.");

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { userId = user.Id, code = code },
                            protocol: Request.Scheme);

                        //  await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                        //     $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
                        await _userManager.AddToRoleAsync(user, MagicStrings.AdminString);

                        await _signInManager.SignInAsync(user, isPersistent : false);

                        string ip = Request.Host.Value;
                        await iPService.Create(new Models.IpDTO(user, ip));

                        return(LocalRedirect(returnUrl));
                    }
                }
                else if (codeService.IsCodeValid(Input.Code))
                {
                    var user = new ACMUser {
                        UserName = Input.Email, Email = Input.Email, FullName = Input.FullName, PhoneNumber = Input.PhoneNumber, AppartentNumber = int.Parse(Input.Code.Split("_")[0])
                    };
                    var result = await _userManager.CreateAsync(user, Input.Password);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created a new account with password.");

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { userId = user.Id, code = code },
                            protocol: Request.Scheme);

                        //  await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                        //     $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                        await _signInManager.SignInAsync(user, isPersistent : false);

                        string ip = Request.Host.Value;
                        await iPService.Create(new Models.IpDTO(user, ip));

                        await codeService.DeleteCode(Input.Code);

                        return(LocalRedirect(returnUrl));
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }