当前位置: 首页>>代码示例>>C#>>正文


C# UserService.GetByUserName方法代码示例

本文整理汇总了C#中UserService.GetByUserName方法的典型用法代码示例。如果您正苦于以下问题:C# UserService.GetByUserName方法的具体用法?C# UserService.GetByUserName怎么用?C# UserService.GetByUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserService的用法示例。


在下文中一共展示了UserService.GetByUserName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authenticate

        /// <summary>
        /// Authenticates the specified user name.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public override Boolean Authenticate( User user, string password )
        {
            byte[] bytes = ConvertToByteArray( user.Password );

            string encodedPassword = EncodePassword( user, password );
            bool valid = encodedPassword == Convert.ToBase64String( bytes );

            bool convert = false;
            if ( valid && Boolean.TryParse( AttributeValue( "ConvertToDatabaseLogin" ), out convert ) && convert )
            {
                // Convert to database type
                var service = new UserService();
                var rockUser = service.GetByUserName( user.UserName );
                if ( rockUser != null )
                {
                    rockUser.Password = DatabaseEncodePassword( password );
                    rockUser.ServiceName = "Rock.Security.Authentication.Database";
                    service.Save( rockUser, null );
                }
            }

            return valid;
        }
开发者ID:jh2mhs8,项目名称:Rock-ChMS,代码行数:29,代码来源:Arena.cs

示例2: Authenticate

        /// <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 = AttributeValue( "AppID" );
                    parameters.client_secret = AttributeValue( "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
                    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
                            {

                                var dvService = new DefinedValueService();

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

                                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;
                                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 = userService.Create( person, AuthenticationServiceType.External, this.GetType().FullName, 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
//.........这里部分代码省略.........
开发者ID:jh2mhs8,项目名称:Rock-ChMS,代码行数:101,代码来源:Facebook.cs


注:本文中的UserService.GetByUserName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。