示例#1
0
        public async Task RunAsync(IRestContext context)
        {
            // IUserApi provides all functions for user management
            IUserApi userApi = context.Factory.CreateUserApi();

            // getSession()
            Session session = await userApi.GetSessionAsync();

            Console.WriteLine("Session ID: {0}", session.session_id);

            // getProfile()
            ProfileResponse profile = await userApi.GetProfileAsync();

            Console.WriteLine("Email from your profile: {0}", profile.email);

            // changePassword()
            const string newPassword = Program.Password + "new";
            bool         ok          = await userApi.ChangePasswordAsync(Program.Password, newPassword);

            if (ok)
            {
                // Changing password back
                if (await userApi.ChangePasswordAsync(newPassword, Program.Password))
                {
                    Console.WriteLine("Password was changed and reverted");
                }
            }
        }
        public void ShouldChangePasswordAsync()
        {
            // Arrange
            IUserApi userApi = CreateUserApi();

            // Act
            bool ok = userApi.ChangePasswordAsync("abc", "cba").Result;

            // Assert
            ok.ShouldBe(true);

            Should.Throw <ArgumentNullException>(() => userApi.ChangePasswordAsync("abc", null));
            Should.Throw <ArgumentNullException>(() => userApi.ChangePasswordAsync(null, "cba"));
        }
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            ClaimsIdentity      identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims   = identity.Claims;

            Task <bool> result;

            if (claims.Any(x => x.Type == ClaimTypes.Role && x.Value == DreamFactoryContext.Roles.SysAdmin))
            {
                result = adminApi.ChangeAdminPasswordAsync(model.OldPassword, model.NewPassword);
            }
            else
            {
                result = userApi.ChangePasswordAsync(model.OldPassword, model.NewPassword);
            }

            if (await result)
            {
                ViewBag.StatusMessage = "Your password has been changed.";
            }
            else
            {
                ViewBag.StatusMessage = "Password was not changed. Please try again.";
            }

            return(View(model));
        }
示例#4
0
        public void ShouldChangePasswordAsync()
        {
            // Arrange
            IUserApi userApi = CreateUserApi();

            // Act
            bool ok = userApi.ChangePasswordAsync("abc", "cba").Result;

            // Assert
            ok.ShouldBe(true);
        }