コード例 #1
0
ファイル: PersonEdit.ascx.cs プロジェクト: rowlek/Rock-ChMS
        protected void btnUpdate_Click( object sender, EventArgs e )
        {
            if ( Page.IsValid )
            {
                Person person;

                string personId = ( string )Page.RouteData.Values["PersonId"] ?? string.Empty;
                if ( string.IsNullOrEmpty( personId ) )
                    personId = Request.QueryString["PersonId"];

                PersonService personService = new PersonService();

                if ( !string.IsNullOrEmpty( personId ) )
                    person = personService.Get( Convert.ToInt32( personId ) );
                else
                {
                    person = new Person();
                    personService.Add( person, CurrentPersonId );
                }

                person.GivenName = txtFirstName.Text;
                person.NickName = txtNickName.Text;
                person.LastName = txtLastName.Text;
                if ( person.Guid == Guid.Empty )
                    personService.Add( person, CurrentPersonId );
                personService.Save( person, CurrentPersonId );
            }
        }
コード例 #2
0
ファイル: PersonEdit.ascx.cs プロジェクト: rowlek/Rock-ChMS
        protected void Page_Load( object sender, EventArgs e )
        {
            if ( !IsPostBack )
            {
                Person person;

                string personId = ( string )Page.RouteData.Values["PersonId"] ?? string.Empty;
                if ( string.IsNullOrEmpty( personId ) )
                    personId = Request.QueryString["PersonId"];

                PersonService personService = new PersonService();

                if ( !string.IsNullOrEmpty( personId ) )
                    person = personService.Get( Convert.ToInt32( personId ) );
                else
                {
                    person = new Person();
                    personService.Add( person, CurrentPersonId );
                }

                txtFirstName.Text = person.FirstName;
                txtNickName.Text = person.NickName;
                txtLastName.Text = person.LastName;
            }
        }
コード例 #3
0
ファイル: NewAccount.ascx.cs プロジェクト: rowlek/Rock-ChMS
        private Person CreatePerson()
        {
            Rock.CRM.PersonService personService = new PersonService();

            Person person = new Person();
            person.GivenName = tbFirstName.Text;
            person.LastName = tbLastName.Text;
            person.Email = tbEmail.Text;
            switch(ddlGender.SelectedValue)
            {
                case "M":
                    person.Gender = Gender.Male;
                    break;
                case "F":
                    person.Gender = Gender.Female;
                    break;
                default:
                    person.Gender = Gender.Unknown;
                    break;
            }

            if (ddlBirthMonth.SelectedValue != "0")
                person.BirthMonth = Int32.Parse(ddlBirthMonth.SelectedValue);

            if (ddlBirthDay.SelectedValue != "0")
                person.BirthDay = Int32.Parse(ddlBirthDay.SelectedValue);

            if (ddlBirthYear.SelectedValue != "0")
                person.BirthYear = Int32.Parse(ddlBirthYear.SelectedValue);

            personService.Add(person, CurrentPersonId);
            personService.Save(person, CurrentPersonId);

            return person;
        }
コード例 #4
0
ファイル: Login.ascx.cs プロジェクト: rowlek/Rock-ChMS
        /// <summary>
        /// Awaits permission of facebook user and will issue authenication cookie if successful.
        /// </summary>
        /// <param name="code">Facebook authorization code</param>
        /// <param name="state">Redirect url</param>
        private void ProcessOAuth( string code, string state )
        {
            FacebookOAuthResult oAuthResult;

            if ( FacebookOAuthResult.TryParse( Request.Url, out oAuthResult ) && oAuthResult.IsSuccess )
            {
                try
                {
                    // create client to read response
                    var oAuthClient = new FacebookOAuthClient( FacebookApplication.Current ) { RedirectUri = new Uri( GetOAuthRedirectUrl() ) };
                    oAuthClient.AppId = PageInstance.Site.FacebookAppId;
                    oAuthClient.AppSecret = PageInstance.Site.FacebookAppSecret;
                    dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken( code );
                    string accessToken = tokenResult.access_token;

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

                    // query for matching id in the user table
                    UserService userService = new UserService();
                    var user = userService.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.GivenName == firstName || u.NickName == 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
                            {
                                person = new Person();
                                person.GivenName = me.first_name.ToString();
                                person.LastName = me.last_name.ToString();
                                person.Email = me.email.ToString();

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

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

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

                            user = userService.Create( person, AuthenticationType.Facebook, 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
                    }

                    // update user record noting the login datetime
                    user.LastLoginDate = DateTime.Now;
                    user.LastActivityDate = DateTime.Now;
                    userService.Save( user, user.PersonId );

                    FormsAuthentication.SetAuthCookie( user.UserName, false );

                    if ( state != null )
                        Response.Redirect( state );

                }
                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.
                }
            }
        }