public function _onload()
 {
     #Get the user session, if no session is given - we skip all of the processing
     #The user could also check the token
     $s = Session::getInstance();
     $u = $s->getUser();
     $t = isset($_GET['token']) ? db()->table('token')->get('token', $_GET['token'])->fetch() : null;
     if (!$u && !$t) {
         return;
     }
     #Export the user to the controllers that may need it.
     $user = $u ? db()->table('user')->get('_id', $u)->fetch() : $t->user;
     $this->user = $user;
     $this->token = $t;
     try {
         #Check if the user is an administrator
         $admingroupid = SysSettingModel::getValue('admin.group');
         $isAdmin = !!db()->table('user\\group')->get('group__id', $admingroupid)->addRestriction('user', $user)->fetch();
     } catch (PrivateException $e) {
         $isAdmin = false;
     }
     $this->isAdmin = $isAdmin;
     $this->view->set('authUser', $this->user);
     $this->view->set('userIsAdmin', $isAdmin);
 }
Example #2
0
 public function logo()
 {
     if ($this->request->isPost() && isset($_POST['file']) && $_POST['file'] instanceof Upload) {
         $location = $_POST['file']->store();
         $img = new spitfire\io\Image($location);
         $img->resize(500);
         $resized = $img->store('./assets/img/' . basename($location));
         SysSettingModel::setValue('page.logo', substr($resized, strlen('./assets/')));
     }
 }
Example #3
0
 public function index()
 {
     if (db()->table('user')->getAll()->count()) {
         throw new spitfire\exceptions\PublicException('Setup was already executed', 403);
     }
     if ($this->request->isPost()) {
         $user = db()->table('user')->newRecord();
         $group = db()->table('group')->newRecord();
         #Create the user
         $user->email = $_POST['email'];
         $user->password = $_POST['password'];
         $user->verified = true;
         $user->created = time();
         $user->store();
         $username = db()->table('username')->newRecord();
         $username->user = $user;
         $username->name = $_POST['username'];
         $username->store();
         #Create the group
         $group->creator = $user;
         $group->name = 'Administrators';
         $group->description = 'System administrators';
         $group->groupId = 'sysadmins';
         $group->public = true;
         $group->open = 0;
         $group->store();
         #Set the group as admin group
         SysSettingModel::setValue('admin.group', $group->_id);
         #Add the user to the group
         $membership = db()->table('user\\group')->newRecord();
         $membership->user = $user;
         $membership->group = $group;
         $membership->role = 'owner';
         $membership->store();
         $this->response->getHeaders()->redirect(new URL());
     }
     //Render the view to create a new user
 }
 public function deliver(\EmailModel $model)
 {
     $post = array();
     $post['from'] = \SysSettingModel::getValue('smtp.from');
     $post['to'] = $model->to;
     $post['subject'] = $model->subject;
     $post['text'] = html_entity_decode(strip_tags($model->body));
     $post['html'] = $model->body;
     #Assemble the curl request
     $ch = curl_init(sprintf('https://api.mailgun.net/v3/%s/messages', $this->domain));
     curl_setopt($ch, CURLOPT_USERPWD, 'api:' . $this->apiKey);
     #Tell curl we're posting and give it the data
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
     #We also want to hear back
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $json = curl_exec($ch);
     $response = $json ? json_decode($json) : false;
     if (!$response) {
         throw new \spitfire\exceptions\PublicException('Invalid response from Mailgun');
     }
     return $response !== false;
 }
Example #5
0
<div class="spacer" style="height: 30px;"></div>

<div class="row1">
	<div class="span1">
		<h1>Current logo</h1>
	</div>
</div>

<div class="row1 material">
	<div class="span1">
		<img src="<?php 
echo URL::asset(SysSettingModel::getValue('page.logo'));
?>
">
	</div>
</div>

<div class="row1">
	<div class="span1">
		<h1>Upload a new logo</h1>
	</div>
</div>

<div class="row1 material">
	<div class="span1">
		<p>Upload a new logo. Recommended dimensions are 722px x 450px</p>
		
		<form method="POST" enctype="multipart/form-data">
			<input type="file" name="file" id="file">
			<input type="submit" value="Upload">
Example #6
0
				<tr>
					<th>Group</th>
					<th>Owner</th>
					<th></th>
				</tr>
			</thead>
			<?php 
foreach ($records as $record) {
    ?>
 
			<tr>
				<td><?php 
    echo __($record->name);
    ?>
 <?php 
    echo $record->_id === SysSettingModel::getValue('admin.group') ? '<i>(Admin)</i>' : '';
    ?>
</td>
				<td><?php 
    echo __($record->creator);
    ?>
</td>
				<td><a href="<?php 
    echo new URL('group', 'detail', $record->_id);
    ?>
">Show</a></td>
			</tr>
			<?php 
}
?>
		</table>