Esempio n. 1
0
        /*=============================================================================
            User handling methods
        =============================================================================*/
        /// <summary>
        /// Adds a new user with given credentials.
        /// </summary>
        /// <param name="userEmail">The email address of the new user.</param>
        /// <param name="userPwd">The password for the new user.</param>
        /// <param name="userType">Whether new user will be administrator or not.</param>
        /// <exception cref="UserNotAdminException">Only administrators can use this method.</exception>
        /// <exception cref="ArgumentNullException">At least one of given email or password is null.</exception>
        /// <exception cref="InvalidEmailException">Given email is not syntactically correct.</exception>
        /// <exception cref="InvalidPasswordException">Given password is shorter than MinPasswordLength.</exception>
        /// <exception cref="UserNotLoggedInException">A user must be logged in to use this method.</exception>
        /// <exception cref="UserExistingException">A user with given email address already exists.</exception>
        public void AddUser(string userEmail, string userPwd, UserType userType)
        {
            // Requirements
            Require.ValidEmail(userEmail, "userEmail");
            Require.ValidPassword(userPwd, "userPwd");
            RequireLoggedInUser();
            RequireAdminUser();
            RequireNotExistingUser(userEmail);

            var userId = GenerateUserId(userType);
            var user = new User(userId, userEmail, userPwd, userType);

            _users.AddEntity(user);
            _users.SaveChanges();
        }
Esempio n. 2
0
        private static void SetupUsersTable(string tableEndpointUri, StorageCredentials credentials)
        {
            PrintStep("Creating users table...");
            AzureTable<User>.Create(tableEndpointUri, credentials);
            var usersTable = AzureTable<User>.Connect(tableEndpointUri, credentials);
            if (_doReset)
                usersTable.Clear();

            PrintStep(" * Adding default users");

            var q = usersTable.Entities.Where(u => u.RowKey == "a0").ToList();
            if (q.Any()) return;

            var defaultAdminEmail = Settings.Default.DefaultAdminEmail;
            var defaultAdminPwd = Settings.Default.DefaultAdminPwd;
            var defaultAdminUser = new User("a0", defaultAdminEmail, defaultAdminPwd, UserType.AdminUser);

            usersTable.AddEntity(defaultAdminUser);
            usersTable.SaveChanges();
        }