Create() public static method

Creates a new Rock.Model.UserLogin
Thrown when the Username already exists. Thrown when the service does not exist or is not active.
public static Create ( RockContext rockContext, Rock person, AuthenticationServiceType serviceType, int entityTypeId, string username, string password, bool isConfirmed ) : UserLogin
rockContext RockContext The rock context.
person Rock The that this will be associated with.
serviceType AuthenticationServiceType The type of Login
entityTypeId int The entity type identifier.
username string A containing the UserName.
password string A containing the unhashed/unencrypted password.
isConfirmed bool A flag indicating if the user has been confirmed.
return UserLogin
Beispiel #1
0
        private Rock.Model.UserLogin CreateUser(Person person, bool confirmed)
        {
            var userLoginService = new Rock.Model.UserLoginService();

            return(userLoginService.Create(person, Rock.Model.AuthenticationServiceType.Internal,
                                           EntityTypeCache.Read(Rock.SystemGuid.EntityType.AUTHENTICATION_DATABASE.AsGuid()).Id,
                                           tbUserName.Text, Password, confirmed, CurrentPersonId));
        }
Beispiel #2
0
 /// <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));
 }
Beispiel #3
0
        private Rock.Model.UserLogin CreateUser(Person person, bool confirmed)
        {
            var userLoginService = new Rock.Model.UserLoginService();

            return(userLoginService.Create(person, Rock.Model.AuthenticationServiceType.Internal, "Rock.Security.Authentication.Database", tbUserName.Text, Password, confirmed, CurrentPersonId));
        }
Beispiel #4
0
 private Rock.Model.UserLogin CreateUser( Person person, bool confirmed )
 {
     var userLoginService = new Rock.Model.UserLoginService();
     return userLoginService.Create( person, Rock.Model.AuthenticationServiceType.Internal, 
         EntityTypeCache.Read(Rock.SystemGuid.EntityType.AUTHENTICATION_DATABASE.AsGuid()).Id, 
         tbUserName.Text, Password, confirmed, CurrentPersonId );
 }
Beispiel #5
0
        /// <summary>
        /// Authenticates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="username">The username.</param>
        /// <param name="returnUrl">The return URL.</param>
        /// <returns></returns>
        public override Boolean Authenticate( HttpRequest request, out string username, out string returnUrl )
        {
            var fbClient = new FacebookClient();
            FacebookOAuthResult oAuthResult;

            if ( fbClient.TryParseOAuthCallbackUrl( request.Url, out oAuthResult ) && oAuthResult.IsSuccess )
            {
                try
                {
                    var redirectUri = new Uri( GetRedirectUrl( request ) );

                    dynamic parameters = new ExpandoObject();
                    parameters.client_id = GetAttributeValue( "AppID" );
                    parameters.client_secret = GetAttributeValue( "AppSecret" );
                    parameters.redirect_uri = redirectUri.AbsoluteUri; 
                    parameters.code = oAuthResult.Code;

                    dynamic result = fbClient.Post( "oauth/access_token", parameters );

                    string accessToken = result.access_token;

                    fbClient = new FacebookClient( accessToken );
                    dynamic me = fbClient.Get( "me" );
                    string facebookId = "FACEBOOK_" + me.id.ToString();

                    // query for matching id in the user table 
                    var userLoginService = new UserLoginService();
                    var user = userLoginService.GetByUserName( facebookId );

                    // if not user was found see if we can find a match in the person table
                    if ( user == null )
                    {
                        try
                        {
                            // determine if we can find a match and if so add an user login record

                            // get properties from Facebook dynamic object
                            string lastName = me.last_name.ToString();
                            string firstName = me.first_name.ToString();
                            string email = me.email.ToString();

                            var personService = new PersonService();
                            var person = personService.Queryable().FirstOrDefault( u => u.LastName == lastName && u.FirstName == firstName && u.Email == email );

                            if ( person != null )
                            {
                                // since we have the data enter the birthday from Facebook to the db if we don't have it yet
                                DateTime birthdate = Convert.ToDateTime( me.birthday.ToString() );

                                if ( person.BirthDay == null )
                                {
                                    person.BirthDate = birthdate;
                                    personService.Save( person, person.Id );
                                }

                            }
                            else
                            {

                                var dvService = new DefinedValueService();

                                person = new Person();
                                person.IsSystem = false;
                                person.RecordTypeValueId = dvService.GetIdByGuid( new Guid( SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ) );
                                person.RecordStatusValueId = dvService.GetIdByGuid( new Guid( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ) );

                                person.FirstName = me.first_name.ToString();
                                person.LastName = me.last_name.ToString();
                                person.Email = me.email.ToString();

                                if ( me.gender.ToString() == "male" )
                                    person.Gender = Gender.Male;
                                else if ( me.gender.ToString() == "female" )
                                    person.Gender = Gender.Female;
                                else
                                    person.Gender = Gender.Unknown;

                                person.BirthDate = Convert.ToDateTime( me.birthday.ToString() );
                                person.DoNotEmail = false;

                                personService.Add( person, null );
                                personService.Save( person, null );
                            }

                            user = userLoginService.Create( person, AuthenticationServiceType.External, this.TypeId, facebookId, "fb", true, person.Id );
                        }
                        catch ( Exception ex )
                        {
                            string msg = ex.Message;
                            // TODO: probably should report something...
                        }

                        // TODO: Show label indicating inability to find user corresponding to facebook id
                    }

                    username = user.UserName;
                    returnUrl = oAuthResult.State;
                    return true;

                }
                catch ( FacebookOAuthException oae )
                {
                    string msg = oae.Message;
                    // TODO: Add error handeling
                    // Error validating verification code. (usually from wrong return url very picky with formatting)
                    // Error validating client secret.
                    // Error validating application.
                }
            }

            username = null;
            returnUrl = null;
            return false;
        }
Beispiel #6
0
        /// <summary>
        /// Handles the Click event of the lbSaveAccount control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSaveAccount_Click( object sender, EventArgs e )
        {
            if ( string.IsNullOrWhiteSpace(TransactionCode))
            {
                nbSaveAccount.Text = "Sorry, the account information cannot be saved as there's not a valid transaction code to reference";
                nbSaveAccount.Visible = true;
                return;
            }

            if ( phCreateLogin.Visible )
            {
                if ( string.IsNullOrWhiteSpace( txtUserName.Text ) || string.IsNullOrWhiteSpace(txtPassword.Text))
                {
                    nbSaveAccount.Title = "Missing Informaton";
                    nbSaveAccount.Text = "A username and password are required when saving an account";
                    nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
                    nbSaveAccount.Visible = true;
                    return;
                }

                if ( new UserLoginService().GetByUserName( txtUserName.Text ) != null )
                {
                    nbSaveAccount.Title = "Invalid Username";
                    nbSaveAccount.Text = "The selected Username is already being used.  Please select a different Username";
                    nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
                    nbSaveAccount.Visible = true;
                    return;
                }

                if ( txtPasswordConfirm.Text != txtPassword.Text )
                {
                    nbSaveAccount.Title = "Invalid Password";
                    nbSaveAccount.Text = "The password and password confirmation do not match";
                    nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
                    nbSaveAccount.Visible = true;
                    return;
                }
            }

            if ( !string.IsNullOrWhiteSpace( txtSaveAccount.Text ) )
            {
                using ( new UnitOfWorkScope() )
                {
                    GatewayComponent gateway = hfPaymentTab.Value == "ACH" ? _achGateway : _ccGateway;
                    var ccCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) );
                    var achCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) );

                    string errorMessage = string.Empty;

                    Person authorizedPerson = null;
                    string referenceNumber = string.Empty;
                    int? currencyTypeValueId = hfPaymentTab.Value == "ACH" ? achCurrencyType.Id : ccCurrencyType.Id;

                    if ( string.IsNullOrWhiteSpace( ScheduleId ) )
                    {
                        var transaction = new FinancialTransactionService().GetByTransactionCode( TransactionCode );
                        if ( transaction != null )
                        {
                            authorizedPerson = transaction.AuthorizedPerson;
                            referenceNumber = gateway.GetReferenceNumber( transaction, out errorMessage );
                        }
                    }
                    else
                    {
                        var scheduledTransaction = new FinancialScheduledTransactionService().GetByScheduleId( ScheduleId );
                        if ( scheduledTransaction != null )
                        {
                            authorizedPerson = scheduledTransaction.AuthorizedPerson;
                            referenceNumber = gateway.GetReferenceNumber( scheduledTransaction, out errorMessage );
                        }
                    }

                    if ( authorizedPerson != null )
                    {
                        if ( phCreateLogin.Visible )
                        {
                            var userLoginService = new Rock.Model.UserLoginService();
                            var user = userLoginService.Create( authorizedPerson, Rock.Model.AuthenticationServiceType.Internal, 
                                EntityTypeCache.Read(Rock.SystemGuid.EntityType.AUTHENTICATION_DATABASE.AsGuid()).Id,
                                txtUserName.Text, txtPassword.Text, false, CurrentPersonId );

                            var mergeObjects = new Dictionary<string, object>();
                            mergeObjects.Add( "ConfirmAccountUrl", RootPath + "ConfirmAccount" );

                            var personDictionary = authorizedPerson.ToDictionary();
                            mergeObjects.Add( "Person", personDictionary );

                            mergeObjects.Add( "User", user.ToDictionary() );

                            var recipients = new Dictionary<string, Dictionary<string, object>>();
                            recipients.Add( authorizedPerson.Email, mergeObjects );

                            var email = new Rock.Communication.Email( GetAttributeValue( "ConfirmAccountTemplate" ) );
                            email.Send( recipients );
                        }

                        var paymentInfo = GetPaymentInfo();

                        if (errorMessage.Any())
                        {
                            nbSaveAccount.Title = "Invalid Transaction";
                            nbSaveAccount.Text = "Sorry, the account information cannot be saved. " + errorMessage;
                            nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
                            nbSaveAccount.Visible = true;
                        }
                        else
                        {
                            var savedAccount = new FinancialPersonSavedAccount();
                            savedAccount.PersonId = authorizedPerson.Id;
                            savedAccount.ReferenceNumber = referenceNumber;
                            savedAccount.Name = txtSaveAccount.Text;
                            savedAccount.MaskedAccountNumber = paymentInfo.MaskedNumber;
                            savedAccount.TransactionCode = TransactionCode;
                            savedAccount.GatewayEntityTypeId = gateway.TypeId;
                            savedAccount.CurrencyTypeValueId = currencyTypeValueId;
                            savedAccount.CreditCardTypeValueId = CreditCardTypeValueId;

                            var savedAccountService = new FinancialPersonSavedAccountService();
                            savedAccountService.Add( savedAccount, CurrentPersonId );
                            savedAccountService.Save( savedAccount, CurrentPersonId );

                            cbSaveAccount.Visible = false;
                            txtSaveAccount.Visible = false;
                            phCreateLogin.Visible = false;
                            divSaveActions.Visible = false;

                            nbSaveAccount.Title = "Success";
                            nbSaveAccount.Text = "The account has been saved for future use";
                            nbSaveAccount.NotificationBoxType = NotificationBoxType.Success;
                            nbSaveAccount.Visible = true;
                        }
                    }
                    else
                    {
                        nbSaveAccount.Title = "Invalid Transaction";
                        nbSaveAccount.Text = "Sorry, the account information cannot be saved as there's not a valid transaction code to reference";
                        nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
                        nbSaveAccount.Visible = true;
                    }
                }
            }
            else
            {
                nbSaveAccount.Title = "Missing Account Name";
                nbSaveAccount.Text = "Please enter a name to use for this account";
                nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
                nbSaveAccount.Visible = true;
            }
        }