コード例 #1
0
ファイル: AccountController.cs プロジェクト: yarivat/Admin
        public IHttpActionResult unlock()
        {
            if (!IsAdmin())
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized, Messages.ActionIsUnauthorized)));
            }

            Durados.Web.Mvc.Controllers.AccountMembershipService accountMembershipService = new Durados.Web.Mvc.Controllers.AccountMembershipService();

            string json = System.Web.HttpContext.Current.Server.UrlDecode(Request.Content.ReadAsStringAsync().Result);

            if (string.IsNullOrEmpty(json))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.FieldNameIsMissing)));
            }
            Dictionary <string, object> data = Durados.Web.Mvc.UI.Json.JsonSerializer.Deserialize(json);

            if (!data.ContainsKey("username"))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.FieldNameIsMissing)));
            }

            string username = data["username"].ToString();

            bool success = accountMembershipService.UnlockUser(username);

            return(Ok(new { success = success }));
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: yarivat/Admin
        protected virtual Dictionary <string, object> ForgotPassword(string newPassword, string confirmPassword, string userSysGuid)
        {
            string usernameForgot  = null;
            string currentPassword = null;

            if (string.IsNullOrEmpty(userSysGuid))
            {
                return(new Dictionary <string, object>()
                {
                    { "success", false }, { "message", "missing user identification" }
                });
            }
            if (string.IsNullOrEmpty(confirmPassword))
            {
                return(new Dictionary <string, object>()
                {
                    { "success", false }, { "message", String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                                     "You must specify a new password of {0} or more characters.",
                                                                     MembershipService.MinPasswordLength) }
                });
            }

            if (!ValidateNewPassword(newPassword, confirmPassword))
            {
                return new Dictionary <string, object>()
                       {
                           { "success", false }, { "message", "Passwords do not match." }
                       }
            }
            ;

            userSysGuid = Durados.Web.Mvc.UI.Helpers.SecurityHelper.GetUserGuidFromTmpGuid(userSysGuid);
            if (string.IsNullOrEmpty(userSysGuid))
            {
                return(new Dictionary <string, object>()
                {
                    { "success", false }, { "message", "User identification is invalid." }
                });
            }
            string guid = GetUserDetail(userSysGuid, Map.Database.UserGuidFieldName); // GetUserDetailsFromGuid(userSysGuid, "[" + Map.Database.UserViewName + "].[" + Map.Database.UserGuidFieldName + "]");

            if (string.IsNullOrEmpty(guid))                                           // &&  guid.Equals(userSysGuid)
            {
                return(new Dictionary <string, object>()
                {
                    { "success", false }, { "message", "User data is invalid." }
                });
            }



            string errorMessage = Map.Database.Localizer.Translate("The current password is incorrect or the new password is invalid.");

            currentPassword = ChangePasswordAfterForgot(userSysGuid, out usernameForgot);
            try
            {
                string username = usernameForgot ?? User.Identity.Name;
                if (MembershipService.ChangePassword(username, currentPassword, newPassword, true))
                {
                    MembershipService.UnlockUser(username);
                    return(new Dictionary <string, object>()
                    {
                        { "success", true }, { "message", "Your password has been changed successfully." }
                    });
                }
                else
                {
                    ModelState.AddModelError("_FORM", errorMessage);
                    return(new Dictionary <string, object>()
                    {
                        { "success", false }, { "message", errorMessage }
                    });
                }
            }
            catch
            {
                ModelState.AddModelError("_FORM", Map.Database.Localizer.Translate("The current password is incorrect or the new password is invalid."));
                return(new Dictionary <string, object>()
                {
                    { "success", false }, { "message", errorMessage }
                });
            }
        }