/// <summary> /// Creates a new <see cref="Rock.Model.UserLogin" /> /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="person">The <see cref="Rock.Model.Person" /> that this <see cref="UserLogin" /> will be associated with.</param> /// <param name="serviceType">The <see cref="Rock.Model.AuthenticationServiceType" /> type of Login</param> /// <param name="entityTypeId">The entity type identifier.</param> /// <param name="username">A <see cref="System.String" /> containing the UserName.</param> /// <param name="password">A <see cref="System.String" /> containing the unhashed/unencrypted password.</param> /// <param name="isConfirmed">A <see cref="System.Boolean" /> flag indicating if the user has been confirmed.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the Username already exists.</exception> /// <exception cref="System.ArgumentException">Thrown when the service does not exist or is not active.</exception> public static UserLogin Create(RockContext rockContext, Rock.Model.Person person, AuthenticationServiceType serviceType, int entityTypeId, string username, string password, bool isConfirmed) { return(UserLoginService.Create(rockContext, person, serviceType, entityTypeId, username, password, isConfirmed, false)); }
/// <summary> /// Creates a new <see cref="Rock.Model.UserLogin"/> /// </summary> /// <param name="person">The <see cref="Rock.Model.Person"/> that this <see cref="UserLogin"/> will be associated with.</param> /// <param name="serviceType">The <see cref="Rock.Model.AuthenticationServiceType"/> type of Login</param> /// <param name="serviceName">A <see cref="System.String"/> representing the service class/type name of the authentication service</param> /// <param name="username">A <see cref="System.String"/> containing the UserName.</param> /// <param name="password">A <see cref="System.String"/> containing the unhashed/unencrypted password.</param> /// <param name="isConfirmed">A <see cref="System.Boolean"/> flag indicating if the user has been confirmed.</param> /// <param name="currentPersonId">A <see cref="System.Int32"/> representing the Id of the <see cref="Rock.Model.Person"/> creating the <see cref="Rock.Model.UserLogin"/></param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the Username already exists.</exception> /// <exception cref="System.ArgumentException">Thrown when the service does not exist or is not active.</exception> public UserLogin Create(Rock.Model.Person person, AuthenticationServiceType serviceType, int entityTypeId, string username, string password, bool isConfirmed, int?currentPersonId) { var entityType = EntityTypeCache.Read(entityTypeId); if (entityType != null) { UserLogin user = this.GetByUserName(username); if (user != null) { throw new ArgumentOutOfRangeException("username", "Username already exists"); } DateTime createDate = DateTime.Now; user = new UserLogin(); user.EntityTypeId = entityTypeId; user.UserName = username; user.IsConfirmed = isConfirmed; user.CreationDateTime = createDate; user.LastPasswordChangedDateTime = createDate; if (person != null) { user.PersonId = person.Id; } if (serviceType == AuthenticationServiceType.Internal) { var authenticationComponent = AuthenticationContainer.GetComponent(entityType.Name); if (authenticationComponent == null || !authenticationComponent.IsActive) { throw new ArgumentException(string.Format("'{0}' service does not exist, or is not active", entityType.FriendlyName), "entityTypeId"); } user.Password = authenticationComponent.EncodePassword(user, password); } this.Add(user, currentPersonId); this.Save(user, currentPersonId); return(user); } else { throw new ArgumentException("Invalid EntityTypeId, entity does not exist", "entityTypeId"); } }
/// <summary> /// Creates a new <see cref="Rock.Model.UserLogin"/> /// </summary> /// <param name="person">The <see cref="Rock.Model.Person"/> that this <see cref="UserLogin"/> will be associated with.</param> /// <param name="serviceType">The <see cref="Rock.Model.AuthenticationServiceType"/> type of Login</param> /// <param name="serviceName">A <see cref="System.String"/> representing the service class/type name of the authentication service</param> /// <param name="username">A <see cref="System.String"/> containing the UserName.</param> /// <param name="password">A <see cref="System.String"/> containing the unhashed/unencrypted password.</param> /// <param name="isConfirmed">A <see cref="System.Boolean"/> flag indicating if the user has been confirmed.</param> /// <param name="currentPersonId">A <see cref="System.Int32"/> representing the Id of the <see cref="Rock.Model.Person"/> creating the <see cref="Rock.Model.UserLogin"/></param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the Username already exists.</exception> /// <exception cref="System.ArgumentException">Thrown when the service does not exist or is not active.</exception> public UserLogin Create( Rock.Model.Person person, AuthenticationServiceType serviceType, int entityTypeId, string username, string password, bool isConfirmed, int? currentPersonId ) { var entityType = EntityTypeCache.Read( entityTypeId ); if ( entityType != null ) { UserLogin user = this.GetByUserName( username ); if ( user != null ) throw new ArgumentOutOfRangeException( "username", "Username already exists" ); DateTime createDate = DateTime.Now; user = new UserLogin(); user.EntityTypeId = entityTypeId; user.UserName = username; user.IsConfirmed = isConfirmed; user.CreationDateTime = createDate; user.LastPasswordChangedDateTime = createDate; if ( person != null ) user.PersonId = person.Id; if ( serviceType == AuthenticationServiceType.Internal ) { var authenticationComponent = AuthenticationContainer.GetComponent( entityType.Name ); if ( authenticationComponent == null || !authenticationComponent.IsActive ) throw new ArgumentException( string.Format( "'{0}' service does not exist, or is not active", entityType.FriendlyName ), "entityTypeId" ); user.Password = authenticationComponent.EncodePassword( user, password ); } this.Add( user, currentPersonId ); this.Save( user, currentPersonId ); return user; } else { throw new ArgumentException( "Invalid EntityTypeId, entity does not exist", "entityTypeId" ); } }
/// <summary> /// Creates a new user. /// </summary> /// <param name="person">The person.</param> /// <param name="serviceType">Type of the service.</param> /// <param name="serviceName">Name of the service.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="isConfirmed">if set to <c>true</c> [is confirmed].</param> /// <param name="currentPersonId">The current person id.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">username;Username already exists</exception> /// <exception cref="System.ArgumentException">serviceName</exception> public UserLogin Create(Rock.Model.Person person, AuthenticationServiceType serviceType, string serviceName, string username, string password, bool isConfirmed, int?currentPersonId) { UserLogin user = this.GetByUserName(username); if (user != null) { throw new ArgumentOutOfRangeException("username", "Username already exists"); } DateTime createDate = DateTime.Now; user = new UserLogin(); user.ServiceType = serviceType; user.ServiceName = serviceName; user.UserName = username; user.IsConfirmed = isConfirmed; user.CreationDate = createDate; user.LastPasswordChangedDate = createDate; if (person != null) { user.PersonId = person.Id; } if (serviceType == AuthenticationServiceType.Internal) { AuthenticationComponent authenticationComponent = GetComponent(serviceName); if (authenticationComponent == null) { throw new ArgumentException(string.Format("'{0}' service does not exist, or is not active", serviceName), "serviceName"); } user.Password = authenticationComponent.EncodePassword(user, password); } this.Add(user, currentPersonId); this.Save(user, currentPersonId); return(user); }
/// <summary> /// Creates a new <see cref="Rock.Model.UserLogin" /> /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="person">The <see cref="Rock.Model.Person" /> that this <see cref="UserLogin" /> will be associated with.</param> /// <param name="serviceType">The <see cref="Rock.Model.AuthenticationServiceType" /> type of Login</param> /// <param name="entityTypeId">The entity type identifier.</param> /// <param name="username">A <see cref="System.String" /> containing the UserName.</param> /// <param name="password">A <see cref="System.String" /> containing the unhashed/unencrypted password.</param> /// <param name="isConfirmed">A <see cref="System.Boolean" /> flag indicating if the user has been confirmed.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the Username already exists.</exception> /// <exception cref="System.ArgumentException">Thrown when the service does not exist or is not active.</exception> public static UserLogin Create(RockContext rockContext, Rock.Model.Person person, AuthenticationServiceType serviceType, int entityTypeId, string username, string password, bool isConfirmed) { if (person != null) { var userLoginService = new UserLoginService(rockContext); var entityType = EntityTypeCache.Read(entityTypeId); if (entityType != null) { UserLogin user = userLoginService.GetByUserName(username); if (user != null) { throw new ArgumentOutOfRangeException("username", "Username already exists"); } DateTime createDate = RockDateTime.Now; user = new UserLogin(); user.Guid = Guid.NewGuid(); user.EntityTypeId = entityTypeId; user.UserName = username; user.IsConfirmed = isConfirmed; user.LastPasswordChangedDateTime = createDate; user.PersonId = person.Id; if (serviceType == AuthenticationServiceType.Internal) { var authenticationComponent = AuthenticationContainer.GetComponent(entityType.Name); if (authenticationComponent == null || !authenticationComponent.IsActive) { throw new ArgumentException(string.Format("'{0}' service does not exist, or is not active", entityType.FriendlyName), "entityTypeId"); } user.Password = authenticationComponent.EncodePassword(user, password); } userLoginService.Add(user); rockContext.SaveChanges(); var historyCategory = CategoryCache.Read(Rock.SystemGuid.Category.HISTORY_PERSON_ACTIVITY.AsGuid(), rockContext); if (historyCategory != null) { var changes = new List <string>(); History.EvaluateChange(changes, "User Login", string.Empty, username); HistoryService.SaveChanges(rockContext, typeof(Person), historyCategory.Guid, person.Id, changes); } return(user); } else { throw new ArgumentException("Invalid EntityTypeId, entity does not exist", "entityTypeId"); } } else { throw new ArgumentException("Invalid Person, person does not exist", "person"); } }
/// <summary> /// Creates a new <see cref="Rock.Model.UserLogin" /> /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="person">The <see cref="Rock.Model.Person" /> that this <see cref="UserLogin" /> will be associated with.</param> /// <param name="serviceType">The <see cref="Rock.Model.AuthenticationServiceType" /> type of Login</param> /// <param name="entityTypeId">The entity type identifier.</param> /// <param name="username">A <see cref="System.String" /> containing the UserName.</param> /// <param name="password">A <see cref="System.String" /> containing the unhashed/unencrypted password.</param> /// <param name="isConfirmed">A <see cref="System.Boolean" /> flag indicating if the user has been confirmed.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the Username already exists.</exception> /// <exception cref="System.ArgumentException">Thrown when the service does not exist or is not active.</exception> public static UserLogin Create( RockContext rockContext, Rock.Model.Person person, AuthenticationServiceType serviceType, int entityTypeId, string username, string password, bool isConfirmed ) { if ( person != null ) { var userLoginService = new UserLoginService( rockContext ); var entityType = EntityTypeCache.Read( entityTypeId ); if ( entityType != null ) { UserLogin user = userLoginService.GetByUserName( username ); if ( user != null ) throw new ArgumentOutOfRangeException( "username", "Username already exists" ); DateTime createDate = RockDateTime.Now; user = new UserLogin(); user.Guid = Guid.NewGuid(); user.EntityTypeId = entityTypeId; user.UserName = username; user.IsConfirmed = isConfirmed; user.LastPasswordChangedDateTime = createDate; user.PersonId = person.Id; if ( serviceType == AuthenticationServiceType.Internal ) { var authenticationComponent = AuthenticationContainer.GetComponent( entityType.Name ); if ( authenticationComponent == null || !authenticationComponent.IsActive ) throw new ArgumentException( string.Format( "'{0}' service does not exist, or is not active", entityType.FriendlyName ), "entityTypeId" ); user.Password = authenticationComponent.EncodePassword( user, password ); } userLoginService.Add( user ); var historyCategory = CategoryCache.Read( Rock.SystemGuid.Category.HISTORY_PERSON_ACTIVITY.AsGuid(), rockContext ); rockContext.WrapTransaction( () => { rockContext.SaveChanges(); if ( historyCategory != null ) { var changes = new List<string>(); History.EvaluateChange( changes, "User Login", string.Empty, username ); HistoryService.SaveChanges( rockContext, typeof( Person ), historyCategory.Guid, person.Id, changes ); } } ); return user; } else { throw new ArgumentException( "Invalid EntityTypeId, entity does not exist", "entityTypeId" ); } } else { throw new ArgumentException( "Invalid Person, person does not exist", "person" ); } }
/// <summary> /// Creates a new <see cref="Rock.Model.UserLogin" /> /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="person">The <see cref="Rock.Model.Person" /> that this <see cref="UserLogin" /> will be associated with.</param> /// <param name="serviceType">The <see cref="Rock.Model.AuthenticationServiceType" /> type of Login</param> /// <param name="entityTypeId">The entity type identifier.</param> /// <param name="username">A <see cref="System.String" /> containing the UserName.</param> /// <param name="password">A <see cref="System.String" /> containing the unhashed/unencrypted password.</param> /// <param name="isConfirmed">A <see cref="System.Boolean" /> flag indicating if the user has been confirmed.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the Username already exists.</exception> /// <exception cref="System.ArgumentException">Thrown when the service does not exist or is not active.</exception> public static UserLogin Create( RockContext rockContext, Rock.Model.Person person, AuthenticationServiceType serviceType, int entityTypeId, string username, string password, bool isConfirmed ) { return UserLoginService.Create( rockContext, person, serviceType, entityTypeId, username, password, isConfirmed, false ); }