Exemplo n.º 1
0
        public void TestDeactivateUser()
        {
            IConfiguration config = getTestConfiguration();

            using (var context = new SGContext(config))
            {
                var token = quickLogin(context, "admin@localhost", "password");
                Assert.IsTrue(token != null, "Unable to log in as admin user.  Test can't run");

                var testUser  = TryCreateUser(context, token, "deactiveUser@localhost", "password2");
                var userToken = quickLogin(context, "deactiveUser@localhost", "password2");
                Assert.IsTrue(userToken != null, "Unable to log in as activation test user.  Test can't run");

                UserTasks.SetUserActiveAsync(context, token, "deactiveUser@localhost", false).Wait();

                var task = LoginTokenTasks.GetLoginTokenAsync(context, userToken.Id);
                task.Wait();
                var userToken2 = task.Result;
                Assert.IsNull(userToken2, "A user's tokens should not be available after deactivation.");

                userToken = quickLogin(context, "deactiveUser@localhost", "password2");
                Assert.IsNull(userToken2, "A user's should not be able to login after deactivation.");

                UserTasks.SetUserActiveAsync(context, token, "deactiveUser@localhost", true).Wait();

                task = LoginTokenTasks.GetLoginTokenAsync(context, userToken.Id);
                task.Wait();
                var userToken3 = task.Result;
                Assert.IsNotNull(userToken3, "User failed to login after reactivation.");
            }
        }
Exemplo n.º 2
0
        private async Task <ApiResult> activateUser_Impl(Int64 tokenId, string email, bool active)
        {
            var token = await quickGetToken(tokenId);

            var userRole = new UserRole(token.User.RawRole);

            if (!userRole.IsAdmin)
            {
                throw AutoApiError.Unauthorised();
            }

            if (string.IsNullOrWhiteSpace(email))
            {
                throw AutoApiError.InvalidParam("email");
            }

            await UserTasks.SetUserActiveAsync(_context, token, email, active);

            return(new ApiResult(StdResult.OK));
        }