public async Task<IActionResult> Recovery(RecoveryModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.Users
                            .Include(u => u.Role)
                            .FirstOrDefaultAsync(u =>
                                                 u.Email == model.Email &&
                                                 u.IsActive == true);
                if (user != null)
                {
                    user.Password = model.ConvertPasswosdToMD5(model.Password);

                    _context.Users.Update(user);
                    await _context.SaveChangesAsync();

                    await Authenticate(user); // аутентификация

                    return RedirectToAction("Index", "Home");
                }//if
              
                //ModelState.AddModelError("", "Некорректные E-mail и(или) пароль");
            }//if

            ViewBag.result = "error";
            return View(model);
        }//Login
Exemple #2
0
        public ActionResult Recovery(RecoveryModel model)
        {
            User user = null;

            if (Manager.IsAuthentication)
            {
                return(Redirect(Url.Action("Index", "Home")));
            }
            else if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else if (!Manager.GetUser(model.Login, out user))
            {
                throw new HttpException(404, "Пользователь не найден");
            }
            else if (!user.ActivationCode.Equals(model.Code))
            {
                ModelState.AddModelError("", "Коды не совпадают");
                return(View(model));
            }
            else
            {
                Manager.UpdatePassword(model.Login, model.newPass);
                return(Redirect(Url.Action("LoginIn")));
            }
        }
        public async Task <HttpResponseMessage> ChangePasswordRecover(RecoveryModel model)
        {
            bool flagFindGuid = false;

            try
            {
                using (SqlConnection connection1 = new SqlConnection(connetionString))
                {
                    await connection1.OpenAsync();

                    string userId = await getIdUserByGuid(connection1, model.recoverCode);

                    if (userId != "")
                    {
                        var            UserManager = Request.GetOwinContext().GetUserManager <ApplicationUserManager>();
                        IdentityResult result      = await UserManager.RemovePasswordAsync(userId);

                        if (result.Succeeded)
                        {
                            result = await UserManager.AddPasswordAsync(userId, model.newPassword);
                        }

                        if (!result.Succeeded)
                        {
                            ErrorModel _errors = new ErrorModel();
                            foreach (string error in result.Errors)
                            {
                                _errors.message = error;
                            }
                            return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
                        }

                        await ChangeFirstTime(connection1, userId);

                        flagFindGuid = true;
                    }
                }
            }
            catch (TransactionAbortedException ex)
            {
                ErrorModel _errors = new ErrorModel();
                _errors.message = ex.Message;
                return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
            }
            catch (ApplicationException ex)
            {
                ErrorModel _errors = new ErrorModel();
                _errors.message = ex.Message;
                return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
            }
            catch (Exception ex)
            {
                ErrorModel _errors = new ErrorModel();
                _errors.message = ex.Message;
                return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
            }

            return(Request.CreateResponse(System.Net.HttpStatusCode.OK, flagFindGuid));
        }
Exemple #4
0
 static public string RecoveryModelText(RecoveryModel recoveryModel)
 {
     return(recoveryModel switch
     {
         RecoveryModel.Full => "Full",
         RecoveryModel.Simple => "Simple",
         RecoveryModel.BulkLogged => "Bulk",
         _ => "Unknown"
     });
Exemple #5
0
        public ActionResult RecoveryStage3(string id)
        {
            RecoveryModel model = new RecoveryModel(WebSSOMode.PasswordRecoveryStage3);

            model.WebApplicationDisplayName = "Web SSO Viewer";
            model.SignOnAttemptId           = id;
            model.CancelAllowed             = true;

            return(View(model));
        }
Exemple #6
0
        public static Database NewDatabaseObject(string dbName, string collation, RecoveryModel recoveryModel)
        {
            var db = new Database(SmoContext.Connection, dbName, SmoContext.Connection.DatabaseEngineEdition)
            {
                Collation     = collation,
                RecoveryModel = recoveryModel,
            };

            return(db);
        }
Exemple #7
0
        public ActionResult RecoveryStage1(string id)
        {
            RecoveryModel model = new RecoveryModel(WebSSOMode.PasswordRecoveryStage1);

            model.WebApplicationDisplayName = "Web SSO Viewer";
            model.SignOnAttemptId           = id;
            model.CancelAllowed             = true;
            model.CaptchaRequired           = true;
            model.CaptchaTheme = CaptchaThemes.clean.ToString();

            return(View(model));
        }
Exemple #8
0
        public ActionResult RecoveryStage2(string id)
        {
            RecoveryModel model = new RecoveryModel(WebSSOMode.PasswordRecoveryStage2);

            model.WebApplicationDisplayName = "Web SSO Viewer";
            model.SignOnAttemptId           = id;
            model.CancelAllowed             = true;

            model.RecoveryQuestion1 = "This would be the first security question?";
            model.RecoveryQuestion2 = "This would be the second security question?";

            return(View(model));
        }
Exemple #9
0
        public ActionResult Recovery(string login, string e_mail)
        {
            if (Manager.IsAuthentication)
            {
                return(Redirect(Url.Action("Index", "Home")));
            }

            RecoveryModel model = new RecoveryModel();

            model.Login  = login;
            model.E_Mail = e_mail;

            return(View(model));
        }
Exemple #10
0
        private static string GetRecoveryModelQuery(RecoveryModel recoveryModel)
        {
            switch (recoveryModel)
            {
            case RecoveryModel.Simple:
                return("SIMPLE");

            case RecoveryModel.BulkLogged:
                return("BULK_LOGGED");

            case RecoveryModel.Default:
            case RecoveryModel.Full:
            default:
                return("FULL");
            }
        }
Exemple #11
0
 public ActionResult Recovery(RecoveryModel model, string returnUrl)
 {
     if (base.ModelState.IsValid)
     {
         try
         {
             string confirmationToken = WebSecurity.GeneratePasswordResetToken(model.UserName, 0x5a0);
             this.SendRegistrationConfirmMail(ConfirmMailOperation.recovery, model.UserName, confirmationToken);
             return(base.RedirectToAction("recoverysuccess", new { returnUrl = returnUrl }));
         }
         catch (Exception)
         {
             base.ModelState.AddModelError("", AccountStrings.AccountRecovery_CannotRecovery);
         }
     }
     return(base.View());
 }
        public string GetRecoveryModelAsString(RecoveryModel recoveryModel)
        {
            string recoveryModelString = string.Empty;

            if (recoveryModel == RecoveryModel.Full)
            {
                recoveryModelString = BackupConstants.RecoveryModelFull;
            }
            else if (recoveryModel == RecoveryModel.Simple)
            {
                recoveryModelString = BackupConstants.RecoveryModelSimple;
            }
            else if (recoveryModel == RecoveryModel.BulkLogged)
            {
                recoveryModelString = BackupConstants.RecoveryModelBulk;
            }

            return(recoveryModelString);
        }
        public RecoveryModel GetRecoveryModel(string databaseName)
        {
            Enumerator en = null;
            DataSet    ds = new DataSet();

            ds.Locale = System.Globalization.CultureInfo.InvariantCulture;
            Request       req           = new Request();
            RecoveryModel recoveryModel = RecoveryModel.Simple;

            en            = new Enumerator();
            req.Urn       = "Server/Database[@Name='" + Urn.EscapeString(databaseName) + "']/Option";
            req.Fields    = new string[1];
            req.Fields[0] = "RecoveryModel";
            ds            = en.Process(this.sqlConnection, req);

            if (ds.Tables[0].Rows.Count > 0)
            {
                recoveryModel = (RecoveryModel)(ds.Tables[0].Rows[0]["RecoveryModel"]);
            }
            return(recoveryModel);
        }
        public ActionResult PasswordRecoveryIndex()
        {
            var model = new RecoveryModel();

            if (Request.QueryString["usr"] == null || Request.QueryString["tok"] == null)
            {
                model.message = General.GetString("CHANGE_PWD_INVALID_URL_ERROR", "You are not allowed to use this functionality witout the correct parameters.");
                model.error   = true;
                return(View("ErrorPasswordRecoveryIndex", model));
            }

            Guid userId;
            Guid token;

            if (!Guid.TryParse(Request.QueryString["usr"].ToString(), out userId) ||
                !Guid.TryParse(Request.QueryString["tok"].ToString(), out token))
            {
                model.message = General.GetString("CHANGE_PWD_INVALID_URL_ERROR", "You are not allowed to use this functionality witout the correct parameters.");
                model.error   = true;
                return(View("ErrorPasswordRecoveryIndex", model));
            }


            Membership.ApplicationName = this.PortalSettings.PortalAlias;
            var membership = (AppleseedMembershipProvider)Membership.Provider;

            if (!membership.VerifyTokenForUser(userId, token))
            {
                model.message = General.GetString("CHANGE_PWD_INVALID_TOKEN_ERROR", "The token is no longer valid.");
                model.error   = true;
                return(View("ErrorPasswordRecoveryIndex", model));
            }

            model.message = General.GetString("CHANGE_PWD_USR_EXPLANATION", "Insert your new password for your account. Once you save the changes you would be able to logon with it.");
            model.UserId  = userId;
            model.token   = token;

            return(View(model));
        }
Exemple #15
0
 private void UpdateRecoveryModel(RecoveryModel recoveryModel)
 {
     try
     {
         using (var con = new SqlConnection(_request.ConnectionString))
         {
             var sql = $"alter database [{con.Database}] set recovery {recoveryModel}";
             using (var cmd = con.CreateCommand())
             {
                 cmd.Connection     = con;
                 cmd.CommandTimeout = _request.ConnectionTimeout;
                 cmd.CommandText    = sql;
                 cmd.CommandType    = CommandType.Text;
                 con.Open();
                 cmd.ExecuteNonQuery();
             }
         }
     }
     catch (Exception)
     {
         //Ok to skip
     }
 }
        public async Task <IActionResult> RecoveryPassword(RecoveryModel model)
        {
            if (model.Email != null)
            {
                var user = await _context.Users
                           .FirstAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("", "Такого Email нет в базе данный");
                    return(View(model));
                }

                var callbackUrl = Url.Action(
                    "Login",
                    "Account",
                    null,
                    protocol: HttpContext.Request.Scheme);
                EmailService emailService = new EmailService();
                await emailService.SendEmailAsync(user.Email, "Ваш пароль на сайте \"WebStore\"",
                                                  $"Ваш пароль на сайте \"WebStore\": <span style=\"background-color: #faebd7\"> {user.Password} </span> <br /> <a href='{callbackUrl}'>Вернуться на сайт</a>");
            }
            return(RedirectToAction("Login", "Account"));
        }
        public ActionResult RecoveryStage1(string id)
        {
            RecoveryModel model = new RecoveryModel(WebSSOMode.PasswordRecoveryStage1);
            model.WebApplicationDisplayName = "Web SSO Viewer";
            model.SignOnAttemptId = id;
            model.CancelAllowed = true;
            model.CaptchaRequired = true;
            model.CaptchaTheme = CaptchaThemes.clean.ToString();

            return View(model);
        }
 public static void Create(string databaseName, RecoveryModel recoveryModel, string collation) => new CreateDatabaseTask(databaseName, recoveryModel, collation).Execute();
 public CreateDatabaseTask(string databaseName, RecoveryModel recoveryModel, string collation) : this(databaseName, recoveryModel)
 {
     Collation = collation;
 }
 public CreateDatabaseTask(string databaseName, RecoveryModel recoveryModel) : this(databaseName)
 {
     RecoveryModel = recoveryModel;
 }
 public static void Create(IConnectionManager connectionManager, string databaseName, RecoveryModel recoveryModel, string collation)
 => new CreateDatabaseTask(databaseName, recoveryModel, collation)
 {
     ConnectionManager = connectionManager
 }.Execute();
Exemple #22
0
        /// <summary>
        /// Return recovery model of the database
        /// </summary>
        /// <returns></returns>
        public string GetRecoveryModel(string databaseName)
        {
            RecoveryModel recoveryModel = this.backupRestoreUtil.GetRecoveryModel(databaseName);

            return(recoveryModel.ToString());
        }
        public ActionResult RecoveryStage3(string id)
        {
            RecoveryModel model = new RecoveryModel(WebSSOMode.PasswordRecoveryStage3);
            model.WebApplicationDisplayName = "Web SSO Viewer";
            model.SignOnAttemptId = id;
            model.CancelAllowed = true;

            return View(model);
        }
        public ActionResult RecoveryStage2(string id)
        {
            RecoveryModel model = new RecoveryModel(WebSSOMode.PasswordRecoveryStage2);
            model.WebApplicationDisplayName = "Web SSO Viewer";
            model.SignOnAttemptId = id;
            model.CancelAllowed = true;

            model.RecoveryQuestion1 = "This would be the first security question?";
            model.RecoveryQuestion2 = "This would be the second security question?";

            return View(model);
        }
Exemple #25
0
 private void UpdateRecoveryModel(RecoveryModel recoveryModel)
 {
     try
     {
         using (var con = new SqlConnection(_request.ConnectionString))
         {
             var sql = $"alter database [{con.Database}] set recovery {recoveryModel}";
             using (var cmd = con.CreateCommand())
             {
                 cmd.Connection = con;
                 cmd.CommandTimeout = _request.ConnectionTimeout;
                 cmd.CommandText = sql;
                 cmd.CommandType = CommandType.Text;
                 con.Open();
                 cmd.ExecuteNonQuery();
             }
         }
     }
     catch (Exception)
     {
         //Ok to skip
     }
 }
 private static string GetRecoveryModelQuery(RecoveryModel recoveryModel)
 {
     switch (recoveryModel)
     {
         case RecoveryModel.Simple:
             return "SIMPLE";
         case RecoveryModel.BulkLogged:
             return "BULK_LOGGED";
         case RecoveryModel.Default:
         case RecoveryModel.Full:
         default:
             return "FULL";
     }
 }