Exemplo n.º 1
0
        /// <summary>
        /// Set modelState within current errors
        /// </summary>
        /// <param name="modelState"></param>
        /// <param name="ressources"></param>
        /// <param name="errors"></param>
        protected void SetModelState(ModelStateDictionary modelState, LanguageDictionary ressources, Errors errors)
        {
            modelState.Clear();

            foreach (KeyValuePair <string, List <Error> > field in errors.Fields)
            {
                foreach (Error error in field.Value)
                {
                    modelState.AddModelError(field.Key, ressources.GetLabel(ressources.DefaultLanguage, error.Message, error.Parameters));
                }
            }

            foreach (Error error in errors.Global)
            {
                modelState.AddModelError("", ressources.GetLabel(ressources.DefaultLanguage, error.Message, error.Parameters));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send an email on asking a new password
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public UserRecord SendNewPassword(string login)
        {
            // ask for a new password due to forget password

            try
            {
                UserRecord user = _userManager.AskNewPassword(login);

                // read the multilingual dictionary

                LanguageDictionary ressources = new LanguageDictionary(Server?.MapPath(LanguageDictionary.DIRECTORY_IMAGE), ConfigurationManager.DefaultLanguage);
                ressources.Load(_userManager.Database, user.CustomerId);

                // Send an email to the user within a link towards the new password page

                MailMessage message = new MailMessage();
                message.To.Add(new MailAddress(user.Email));
                message.Subject = ressources.GetLabel(user.Language, "USER_NEW_PASSWORD");

                string body;
                // TODO: Replace this code by a render HTML
                UserViewModel Model = new UserViewModel(ressources, user, false);
                // message.Body = RenderManager.RenderView("~/Areas/Administration/Views/User/MailNewPassword.cshtml", new UserViewModel(ressources, user, false));
                body =
                    $"<center><img src=\"{Model.UrlRoot}Content/Images/Areas/Administration/User/MailNewPassword/Logo.png\" width=\"200px\" height=\"50px\"/></center>" +
                    "<p>" +
                    "Pour réinitialiser le mot de passe, veuillez cliquer sur le lien suivant:" +
                    "<ul>" +
                    $"<li><a href=\"{Model.UrlRoot}Administration/User/NewPassword?key={Model.UserProfile.NewPasswordKey}\">Réinitialisation du mot de passe</a></li>" +
                    $"<li>Identifiant : {Model.UserProfile.Login}</li>";
                if (Model.Mode != "PROD")
                {
                    body += $"<li>Instance : <a href=\"{Model.UrlRoot}\">{Model.UrlRoot}</a></li>";
                    body += $"<li>Mode : {Model.Mode}</li>";
                }
                body += "</ul></p>";

                message.Body         = body;
                message.BodyEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
                message.IsBodyHtml   = true;

                using (var smtp = new SmtpClient())
                    smtp.Send(message);

                return(user);
            }
            catch (System.Exception ex)
            {
                Exception($"An exception occurs on asking for a new password due to {ex.Message}", ex);
                return(null);
            }
        }