Example #1
0
	function delete_view ($instance, &$context) {
		
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			
			if ($_POST['delete']) {
				// Deletes the instance
				$instance->delete();
				
				// Return to the item listing page for this model  (with 'deleted' message)
				redir('../../?msg=deleted');
			}
			else {
				// Return to the item listing page (without 'deleted' message)
				redir('../../');
			}
			
			
		}
		
		// Create the form
		$f = new Form();
		$f->add_fields(array(
			'yes' => new SubmitField('Yes'),
			'no' => new SubmitField('No'),
		));
		$context['form'] = $f;
		
	}
Example #2
0
	function contact () {
		
		if ($_GET['sent']) {
			return $this->page('contact', array('sent' => True));
		}
		
		$f = new Form();
		$f->add_fields(array(
			'name' => new CharField('Name', array('length' => 100)),
			'email' => new CharField('E-mail', array('length' => 100)),
			'message' => new TextField('Message'),
		));
		
		$context = array(
			'contact_form' => $f,
		);
		
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			
			$f->input($_POST);
			
			if ( !($_POST['name'] && $_POST['email'] && $_POST['message']) ) {
				$context['error'] = 'All fields are required. Please complete the form.';
			}
			elseif (!validate_email($_POST['email'])) {
				$context['error'] = 'Invalid e-mail address.';
			}
			else {
				
				// Get e-mail address from the Settings app
				$to = Frix::app('settings')->get('contact_email');
				
				// Send the e-mail
				$ok = send_mail('Contact', $f->get_message(), $f->get_email(), $to);
				
				// Error sending the message?
				if (!$ok) {
					$context['error'] = 'Couldn\'t send message, please try again later.';
				}
				else {
					redir('./?sent=1');
				}
				
			}
			
		}
		
		return $this->page('contact', $context);
		
	}
Example #3
0
	function forgot () {
		
		// Load Auth app
		$auth_app = Frix::app('auth');
		
		// Already authorized?
		if ($auth_app->get_user()) {
			// Go to the admin home
			redir(url(self::$root));
		}
		
		// Load AuthUser model
		$auth_app->load_model('AuthUser');
		// Get model meta
		$meta = AuthUser::meta();
		
		$f = new Form;
		$f->add_fields(array(
			'email' => new CharField('E-mail', array('length' => 100)),
		));
		
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			
			// Get form data
			$f->input($_POST);
			
			$email = $f->get_email();
			
			// Check for a valid e-mail address.
			if (!validate_email($email)) {
				self::$context['msg'] = sprintf('Invalid e-mail address "%s"!', $email);
				self::$context['msg_type'] = 'err';
			}
			else {
				// Get user by e-mail address
				$user = $meta->one(array('email' => $email));
				
				if ($user) {
					
					// Create a new password
					$pass = make_pass();
					
					$msg =
						'Your new passord is:' . "\n" .
						$pass . "\n\n" .
						'You can log in using your username:'******'New password', $msg, Frix::app('settings')->get('contact_email'), $user->email);
					
					// Error sending the msg?
					if (!$ok) {
						self::$context['msg'] =
							'Couldn\'t send msg.<br />' .
							'Password not changed.'
						;
						self::$context['msg_type'] = 'err';
					}
					// Message sucessfully sent?
					else {
						// Change user password and save
						$user->set_password($pass);
						$user->save();
						// Redirect with a success msg
						redir('./?sent=1');
					}
					
				}
				else {
					self::$context['msg'] = sprintf('E-mail address "%s" not found!', $email);
					self::$context['msg_type'] = 'err';
				}
			}
			
		}
		else {
			if ($_GET['sent']) {
				self::$context['msg'] =
					'The new password was sent!<br />'.
					'Please check your inbox.'
				;
				self::$context['msg_type'] = 'ok';
			}
			else {
				self::$context['msg'] = 'Type your e-mail to get a new password.';
			}
		}
		
		self::$context['form'] = $f;
		
		$t = new Template('frix/admin/forgot');
		echo $t->render(self::$context);
		
	}