Exemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            CaptchaResponse response = CaptchaHelper.ValidateCaptcha(Request["g-recaptcha-response"]);

            if (!response.Success)
            {
                return(RedirectToAction("CaptchaInvalid", "Home"));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Owner");
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    this.RegisterOwner(user.Id, model.FirstName, model.LastName, model.Email);

                    //await SendConfirmationEmailAsync(user.Id);
                    await SendConfirmationEmailAsync(user.Id, model.FirstName, model.LastName, model.Email, model.Password);

                    return(RedirectToAction("AccountRegistered"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        public IActionResult Login(UserCredentialsDto dto)
        {
            try
            {
                var captchaValidated = CaptchaHelper.ValidateCaptcha(dto.CaptchaKey, dto.UserCaptchaInput);
                if (captchaValidated == true)
                {
                    var setting = UnitOfWork.SettingRepository.GetAll().FirstOrDefault();
                    if (setting == null)
                    {
                        return(StatusCode(500, new { Error = "تنظیمات سیستم تعریف نشده است" }));
                    }

                    var user = UnitOfWork.UserRepository.Find(u => u.UserName == dto.UserName).FirstOrDefault();
                    if (user == null)
                    {
                        return(Unauthorized(new { Error = "نام کاربری یا کلمه عبور اشتباه است" }));
                    }
                    if (UserManager.IsUserLocked(user))
                    {
                        return(Unauthorized(new { Error = "حساب کاربری شما به علت وارد کردن رمز عبور اشتباه بیش از حد مجاز برای دقایقی مسدود شده است." }));
                    }
                    var result = UserManager.VerifyPassword(dto.UserName, dto.Password);
                    if (result == "Failed")
                    {
                        UserManager.IncreaseUserFailedPasswordCount(user);
                        if (UserManager.HasUserPassedMaxFailedPasswordCount(user, setting))
                        {
                            UserManager.LockUser(user, setting);
                            UnitOfWork.Complete();
                            return(Unauthorized(new { Error = "حساب کاربری شما به علت وارد کردن رمز عبور اشتباه بیش از حد مجاز برای دقایقی مسدود شده است." }));
                        }
                        UnitOfWork.Complete();
                        return(Unauthorized(new { Error = "نام کاربری یا کلمه عبور اشتباه است" }));
                    }
                    UserManager.UnlockUser(user);

                    var nextStep = UserManager.GetNextAuthenticationStep(user, SecurityLevel, dto.RequestedSecurityLevel, AuthenticationSteps.Login);
                    if (nextStep == AuthenticationSteps.Done.ToString())
                    {
                        return(new ObjectResult(JwtHandler.Create(user.UserName, dto.RequestedSecurityLevel, dto.ApplicationId, dto.PageId)));
                    }
                    else
                    {
                        return(Ok(new { NextRoute = nextStep }));
                    }
                }
                else
                {
                    return(StatusCode(400, new { Error = "کلید تصویر امنیتی معتبر نمی باشد" }));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Exemplo n.º 3
0
 public IActionResult ForgotPassword(ForgotPasswordDto dto)
 {
     try
     {
         var captchaValidated = CaptchaHelper.ValidateCaptcha(dto.CaptchaKey, dto.UserCaptchaInput);
         if (captchaValidated == true)
         {
             var decryptedEmail        = CryptographyHelper.Decrypt(dto.EncryptedEmail);
             var decryptedMobileNumber = CryptographyHelper.Decrypt(dto.EncryptedMobileNumber);
             // send to email
             // send to mobile
             return(Ok());
         }
         else
         {
             return(StatusCode(400, new { Error = "کلید تصویر امنیتی معتبر نمی باشد" }));
         }
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
Exemplo n.º 4
0
 public IActionResult Create(UserCreateDto dto)
 {
     try
     {
         var captchaValidated = CaptchaHelper.ValidateCaptcha(dto.CaptchaKey, dto.UserCaptchaInput);
         if (captchaValidated == true)
         {
             //Create Person if not exists
             var user = UnitOfWork.UserRepository.Find(u => u.UserName == dto.UserName).FirstOrDefault();
             if (user == null)
             {
                 if (!CustomValidator.CheckPasswordComplexity(dto.Password))
                 {
                     return(BadRequest(new { Error = "رمز عبور باید حداقل 8 کاراکتر و ترکیبی از اعداد و حروف باشد" }));
                 }
                 if (!CustomValidator.ValidateNationalCode(dto.UserName))
                 {
                     return(BadRequest(new { Error = "کد ملی معتبر نمی باشد" }));
                 }
                 var result = UserManager.CreateUser(dto);
             }
             else
             {
                 //////////
             }
             return(Ok());
         }
         else
         {
             return(StatusCode(400, new { Error = "کلید تصویر امنیتی معتبر نمی باشد" }));
         }
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }
Exemplo n.º 5
0
        public ActionResult Alert(PetPublicAlertViewModel model)
        {
            //return Content("Error From Google ReCaptcha : " + response.ErrorMessage[0].ToString());
            if (!Request.IsAuthenticated)
            {
                CaptchaResponse response = CaptchaHelper.ValidateCaptcha(Request["g-recaptcha-response"]);
                if (!response.Success)
                {
                    return(RedirectToAction("CaptchaInvalid"));
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (!model.Latitude.HasValue && !model.Longitude.HasValue)
            {
                this.SetAlertMessageInTempData(AlertMessageTypeEnum.Error, "Su ubicacion no puede ser determinada.");
                return(RedirectToAction("Alert"));
            }

            this.VerifySessionVariables();

            if (User.Identity.IsAuthenticated)
            {
                model.OwnerId = this.GetSessionOwnerId();
            }

            try
            {
                var files = model.Images.ToList();
                if (files.Count > 0)
                {
                    if (!ValidFileExtensions(files))
                    {
                        this.SetAlertMessageInTempData(AlertMessageTypeEnum.Error, "Solo estan permitidos archivos .jpg y .png");
                        return(RedirectToAction("Alert"));
                    }
                    else
                    {
                        var urlImages = new List <string>();
                        model.StaticMapUrl = SaveStaticGoogleMap(model.StaticMapUrl);

                        foreach (var file in files)
                        {
                            var newImageFilePath = this.ResizeAndSaveImage(file);
                            urlImages.Add(newImageFilePath);
                        }

                        //try
                        //{
                        var petAlert = _ownerDataLoader.AddPetPublicAlert(model, urlImages);
                        this.SetAlertMessageInTempData(AlertMessageTypeEnum.Success, "La alerta ha sido guardada.");
                        //}
                        //catch (Exception ex)
                        //{
                        //    this.SetAlertMessageInTempData(AlertMessageTypeEnum.Error, ex.Message);
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                this.SetAlertMessageInTempData(AlertMessageTypeEnum.Error, "Hubo un error en el proceso.");
            }

            return(RedirectToAction("Alert"));
        }