Esempio n. 1
0
        public static async Task <dynamic> ResetUserPassword(string adminId, string id)
        {
            CallContext cctx = Cntx;

            try
            {
                UserServiceProxy usvc = new UserServiceProxy();
                var u = await usvc.LoadEntityByKeyAsync(cctx, id);

                if (u == null)
                {
                    return("");
                }
                var admin = await usvc.LoadEntityByKeyAsync(cctx, adminId);

                var maxadmp = await GetMaxPriority(adminId);

                var maxup = await GetMaxPriority(id);

                if (maxadmp.Major < maxup.Major || maxadmp.Major == maxup.Major && maxadmp.Minor < maxup.Minor)
                {
                    return new { ok = false, msg = string.Format(ResourceUtils.GetString("0452f93e5e52c7eae26c4fac7aa2d5d7", "Denined! Your role level: {0} is less than the requested one."), maxadmp.Major.ToString() + "/" + maxadmp.Minor), newpwd = "" }
                }
                ;
                UserStore <ApplicationUser> store = new UserStore <ApplicationUser>();
                PasswordGenerator           pgen  = new PasswordGenerator();
                var pwd = pgen.Generate();
                while (!pgen.Validate(pwd))
                {
                    pwd = pgen.Generate();
                }
                u.Password = store.HashPassword(pwd);
                if (u.IsPasswordModified)
                {
                    u.LastPasswordChangedDate = DateTime.UtcNow;
                    await usvc.AddOrUpdateEntitiesAsync(cctx, new UserSet(), new User[] { u });
                }
                return(new { ok = true, msg = "", newpwd = pwd });
            }
            catch (Exception e)
            {
                return(new { ok = false, msg = string.Format(ResourceUtils.GetString("49dfe380301a10e682f1b3bc09136542", "Exception: {0}"), e.Message) });
            }
        }
 public static async Task<dynamic> ResetUserPassword(string adminId, string id)
 {
     CallContext cctx = Cntx;
     try
     {
         UserServiceProxy usvc = new UserServiceProxy();
         var u = await usvc.LoadEntityByKeyAsync(cctx, id);
         if (u == null)
             return "";
         var admin = await usvc.LoadEntityByKeyAsync(cctx, adminId);
         var maxadmp = await GetMaxPriority(adminId);
         var maxup = await GetMaxPriority(id);
         if (maxadmp.Major < maxup.Major || maxadmp.Major == maxup.Major && maxadmp.Minor < maxup.Minor)
             return new { ok = false, msg = string.Format(ResourceUtils.GetString("0452f93e5e52c7eae26c4fac7aa2d5d7", "Denined! Your role level: {0} is less than the requested one."), maxadmp.Major.ToString() + "/" + maxadmp.Minor), newpwd = "" };
         UserStore<ApplicationUser> store = new UserStore<ApplicationUser>();
         PasswordGenerator pgen = new PasswordGenerator();
         var pwd = pgen.Generate();
         while (!pgen.Validate(pwd))
             pwd = pgen.Generate();
         u.Password = store.HashPassword(pwd);
         if (u.IsPasswordModified)
         {
             u.LastPasswordChangedDate = DateTime.UtcNow;
             await usvc.AddOrUpdateEntitiesAsync(cctx, new UserSet(), new User[] { u });
         }
         return new { ok = true, msg = "", newpwd = pwd };
     }
     catch (Exception e)
     {
         return new { ok = false, msg = string.Format(ResourceUtils.GetString("49dfe380301a10e682f1b3bc09136542", "Exception: {0}"), e.Message) };
     }
 }
 public ActionResult GeneratePassword()
 {
     PasswordGenerator pgen = new PasswordGenerator();
     return Json(pgen.Generate());
 }