protected void btnChange_Click( object sender, EventArgs e ) { UserService userService = new UserService(); User user = userService.GetByUserName( tbUserName.Text ); if ( user != null ) { if ( userService.ChangePassword( user, tbOldPassword.Text, tbPassword.Text ) ) { userService.Save( user, CurrentPersonId ); lSuccess.Text = AttributeValue( "SuccessCaption" ); pnlEntry.Visible = false; pnlSuccess.Visible = true; } else { lInvalid.Text = AttributeValue( "InvalidPasswordCaption" ); pnlInvalid.Visible = true; } } else { lInvalid.Text = AttributeValue( "InvalidUserNameCaption" ); pnlInvalid.Visible = true; } }
/// <summary> /// Job that updates the JobPulse setting with the current date/time. /// This will allow us to notify an admin if the jobs stop running. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; // delete accounts that have not been confirmed in X hours int userExpireHours = Int32.Parse( dataMap.GetString( "HoursKeepUnconfirmedAccounts" ) ); DateTime userAccountExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1,0,0 ) ); UserService userService = new UserService(); foreach (var user in userService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDate < userAccountExpireDate)) { userService.Delete( user, null ); } userService.Save( null, null ); // purge exception log int exceptionExpireDays = Int32.Parse( dataMap.GetString( "DaysKeepExceptions" ) ); DateTime exceptionExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1, 0, 0 ) ); ExceptionLogService exceptionLogService = new ExceptionLogService(); foreach ( var exception in exceptionLogService.Queryable().Where( e => e.ExceptionDate < exceptionExpireDate ) ) { exceptionLogService.Delete( exception, null ); } exceptionLogService.Save( null, null ); }
/// <summary> /// Validates the user. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns></returns> public static bool Validate( string username, string password ) { UserService service = new UserService(); User user = service.GetByUserName( username ); if ( user != null ) return service.Validate( user, password ); return false; }
public bool Available( string username ) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.UserService UserService = new Rock.CMS.UserService(); User User = UserService.GetByUserName( username ); return ( User == null ); } }
public bool Available(string username) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.UserService UserService = new Rock.CMS.UserService(); User User = UserService.GetByUserName(username); return(User == null); } }
/// <summary> /// Gets the current user. /// </summary> /// <param name="userIsOnline">if set to <c>true</c> [user is online].</param> /// <returns></returns> public static User GetCurrentUser( bool userIsOnline ) { UserService userService = new UserService(); User user = userService.GetByUserName( User.GetCurrentUserName() ); if ( user != null && userIsOnline ) { user.LastActivityDate = DateTime.Now; userService.Save( user, null ); } return user; }
protected void btnSend_Click( object sender, EventArgs e ) { PersonService personService = new PersonService(); var mergeObjects = new List<object>(); var values = new Dictionary<string, string>(); values.Add( "ConfirmAccountUrl", RootPath + "ConfirmAccount" ); mergeObjects.Add( values ); Dictionary<object, List<object>> personObjects = new Dictionary<object, List<object>>(); foreach(Person person in personService.GetByEmail(tbEmail.Text)) { var userObjects = new List<object>(); UserService userService = new UserService(); foreach ( User user in userService.GetByPersonId( person.Id ) ) if ( user.AuthenticationType != AuthenticationType.Facebook ) userObjects.Add( user ); if ( userObjects.Count > 0 ) personObjects.Add( person, userObjects ); } if ( personObjects.Count > 0 ) { mergeObjects.Add( personObjects ); var recipients = new Dictionary<string, List<object>>(); recipients.Add( tbEmail.Text, mergeObjects ); Email email = new Email( Rock.SystemGuid.EmailTemplate.SECURITY_FORGOT_USERNAME ); SetSMTPParameters( email ); email.Send( recipients ); pnlEntry.Visible = false; pnlSuccess.Visible = true; } else pnlWarning.Visible = true; }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnLoad( EventArgs e ) { base.OnLoad( e ); pnlCode.Visible = false; pnlConfirmed.Visible = false; pnlResetPassword.Visible = false; pnlResetSuccess.Visible = false; pnlDelete.Visible = false; pnlDeleted.Visible = false; pnlInvalid.Visible = false; userService = new UserService(); if (!Page.IsPostBack) { lDeleted.Text = AttributeValue( "DeletedCaption" ); string invalidCaption = AttributeValue( "InvalidCaption" ); if ( invalidCaption.Contains( "{0}" ) ) invalidCaption = string.Format( invalidCaption, ResolveUrl( "~/NewAccount" ) ); lInvalid.Text = invalidCaption; ConfirmationCode = Request.QueryString["cc"]; user = userService.GetByConfirmationCode( ConfirmationCode ); string action = Request.QueryString["action"] ?? ""; switch ( action.ToLower() ) { case "delete": ShowDelete(); break; case "reset": ShowResetPassword(); break; default: ShowConfirmed(); break; } } }
/// <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. } } }