Beispiel #1
0
        public override void AfterDatabaseInitialized()
        {
            base.AfterDatabaseInitialized();

            var dbc = AppConfig.DatabaseCreation;

            if (!string.IsNullOrEmpty(dbc.AdminUserFirstName) && !string.IsNullOrEmpty(dbc.AdminUserLastName) && !string.IsNullOrEmpty(dbc.AdminUserEmail) && !string.IsNullOrEmpty(dbc.AdminUserPassword))
            {
                AuthProvider.AddUser(dbc.AdminUserFirstName, dbc.AdminUserLastName, dbc.AdminUserEmail, dbc.AdminUserEmail, dbc.AdminUserPassword, RoleType.Admin);
            }

            if (!string.IsNullOrEmpty(dbc.AdminUserFirstName) && !string.IsNullOrEmpty(dbc.AdminUserLastName) && !string.IsNullOrEmpty(dbc.AdminUserEmail) && !string.IsNullOrEmpty(dbc.AdminUserPassword))
            {
                AuthProvider.AddUser(dbc.AdminUserFirstName2, dbc.AdminUserLastName2, dbc.AdminUserEmail2, dbc.AdminUserEmail2, dbc.AdminUserPassword2, RoleType.Admin);
            }

            for (int i = 0; i < dbc.TestUsersCount; i++)
            {
                AuthProvider.AddUser("Test", $"User {i}", $"testuser{i}@gmail.com", $"testuser{i}@gmail.com", dbc.TestUsersPassword, RoleType.User);
            }

            for (int i = 0; i < dbc.TestManagersCount; i++)
            {
                AuthProvider.AddUser("Test", $"Manager {i}", $"testmanager{i}@gmail.com", $"testmanager{i}@gmail.com", dbc.TestUsersPassword, RoleType.Manager);
            }
        }
Beispiel #2
0
        public override void InitializeDatabase()
        {
            try
            {
                var config = AppConfig.DatabaseCreation;

                // Initialize default identity roles
                foreach (var role in RoleTypeHelper.AllRoles)
                {
                    AuthProvider.CreateRole(role);
                }

                // Initialize default user

                // Admin
                if (!string.IsNullOrEmpty(config.AdminUserFirstName))
                {
                    AuthProvider.AddUser(config.AdminUserFirstName, config.AdminUserLastName, config.AdminUserEmail, config.AdminUserEmail, config.AdminUserPassword, RoleType.Admin);
                }

                if (!string.IsNullOrEmpty(config.AdminUserFirstName2))
                {
                    AuthProvider.AddUser(config.AdminUserFirstName2, config.AdminUserLastName2, config.AdminUserEmail2, config.AdminUserEmail2, config.AdminUserPassword2, RoleType.Admin);
                }

                // User manager
                for (int i = 1; i <= config.TestManagersCount; i++)
                {
                    AuthProvider.AddUser("Manager", i.ToString(), $"manager{i}@gmail.com", $"manager{i}@gmail.com", config.TestUsersPassword, RoleType.Manager);
                }

                // User
                for (int i = 1; i <= config.TestUsersCount; i++)
                {
                    AuthProvider.AddUser("User", i.ToString(), $"user{i}@gmail.com", $"user{i}@gmail.com", config.TestUsersPassword, RoleType.User);
                }
            }
#if DEBUG
            catch (Exception ex)
            {
                throw ex;
            }
#else
            catch
            {
                throw;
            }
#endif
        }
Beispiel #3
0
 /// <summary>
 /// Saves modified user data into the ASP Net Identity database
 /// </summary>
 public void Add(User user)
 {
     AuthProvider.AddUser(user.FirstName, user.LastName, user.UserName, user.Email, user.Password, user.Role);
     user.UserId = GetByUserName(user.UserName).UserId; // this is dnoe by EF, but we have to do it manually here
 }