Beispiel #1
0
        public static async Task ChangeAccountInfo(string id, ApplicationUser user)
        {
            var cntx = Cntx;
            UserServiceProxy usvc = new UserServiceProxy();
            var u = await usvc.LoadEntityByKeyAsync(cntx, id);

            if (u == null)
            {
                return;
            }
            u.FirstName = user.FirstName;
            u.LastName  = user.LastName;
            if (u.IsFirstNameModified || u.IsLastNameModified)
            {
                await usvc.AddOrUpdateEntitiesAsync(cntx, new UserSet(), new User[] { u });
            }
            if (!string.IsNullOrEmpty(user.Email))
            {
                UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy();
                var mb = await mbsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.App.ID, id);

                if (mb != null)
                {
                    mb.Email = user.Email;
                    if (mb.IsEmailModified)
                    {
                        await mbsvc.AddOrUpdateEntitiesAsync(cntx, new UserAppMemberSet(), new UserAppMember[] { mb });
                    }
                }
            }
        }
Beispiel #2
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 ChangeAccountInfo(string id, ApplicationUser user)
 {
     var cntx = Cntx;
     UserServiceProxy usvc = new UserServiceProxy();
     var u = await usvc.LoadEntityByKeyAsync(cntx, id);
     if (u == null)
         return;
     u.FirstName = user.FirstName;
     u.LastName = user.LastName;
     if (u.IsFirstNameModified || u.IsLastNameModified)
         await usvc.AddOrUpdateEntitiesAsync(cntx, new UserSet(), new User[] { u });
     if (!string.IsNullOrEmpty(user.Email))
     {
         UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy();
         var mb = await mbsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.App.ID, id);
         if (mb != null)
         {
             mb.Email = user.Email;
             if (mb.IsEmailModified)
                 await mbsvc.AddOrUpdateEntitiesAsync(cntx, new UserAppMemberSet(), new UserAppMember[] { mb });
         }
     }
 }
 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) };
     }
 }