Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
202 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace pixelpost\plugins\auth\classes; | ||
|
||
use pixelpost\core\Request, | ||
pixelpost\core\Template, | ||
pixelpost\plugins\api\Plugin as Api; | ||
|
||
class UserForm | ||
{ | ||
public $flag_reconnect = false; | ||
public $flag_success = false; | ||
public $is_online = false; | ||
public $user_id = null; | ||
|
||
public function __construct($user_id, $is_online = false) | ||
{ | ||
$this->user_id = $user_id; | ||
$this->is_online = $is_online; | ||
} | ||
|
||
/** | ||
* Check if the form is posted and process posted data | ||
* | ||
* @param pixelpost\core\Request $request | ||
* @return bool TRUE if a form is posted else false | ||
*/ | ||
public function check(Request $request) | ||
{ | ||
if (!$request->is_post()) return false; | ||
|
||
// retrieve posted data in $p | ||
$p = filter_var_array($request->get_post(), array( | ||
'name' => array('filter' => FILTER_SANITIZE_STRING), | ||
'email' => array('filter' => FILTER_VALIDATE_EMAIL), | ||
'password' => array('filter' => FILTER_SANITIZE_STRING), | ||
)); | ||
|
||
// delete not provided and bad value | ||
if (!$p['name']) unset($p['name']); | ||
if (!$p['email']) unset($p['email']); | ||
if (!$p['password']) unset($p['password']); | ||
|
||
// remove name if not changed (for error in api next call: same name) | ||
if (isset($p['name']) && $p['name'] === $this->user_id) | ||
{ | ||
unset($p['name']); | ||
} | ||
|
||
// make the update | ||
Api::call_api_method('auth.user.set', $p + array('user' => $this->user_id)); | ||
|
||
// update some flag | ||
$this->flag_success = true; | ||
$this->flag_reconnect = ($this->is_online and isset($p['name']) || isset($p['password'])); | ||
|
||
// update the user id if needed | ||
if (isset($p['name'])) | ||
{ | ||
$this->user_id = $p['name']; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Create a Html5 form | ||
* | ||
* @param array|object $user the user data (user, name, email) | ||
* @return string The HTML5 form | ||
*/ | ||
public function render($user) | ||
{ | ||
return Template::create() | ||
->assign(array('user' => $user, 'form' => $this)) | ||
->render('auth/tpl/_user-form.tpl'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div class="entity well well-small"> | ||
<p> | ||
<strong>{{ entity.name }}</strong> | ||
<span class="hide">—</span> | ||
<span class="pull-right"> | ||
<a class="btn btn-info btn-mini" data-toggle="collapse" data-parent="#entities" href="#{{ entity.entity }}"> | ||
<i class="icon-list icon-white"></i> info | ||
</a> | ||
<span class="hide">—</span> | ||
<a class="btn btn-danger btn-mini"> | ||
<i class="icon-remove icon-white"></i> delete | ||
</a> | ||
</span> | ||
</p> | ||
<form id="{{ entity.entity }}" class="collapse form-inline"> | ||
<table class="table table-condensed"> | ||
<tr> | ||
<th>Public key</th> | ||
<td>{{ entity.public_key }}</td> | ||
</tr> | ||
<tr> | ||
<th>Private key</th> | ||
<td>{{ entity.private_key }}</td> | ||
</tr> | ||
<tr> | ||
<th>Grants</th> | ||
<td> | ||
{% for g in grants %} | ||
<label class="checkbox inline"> | ||
<input type="checkbox" value="{{ g.grant }}"> {{ g.name }} | ||
</label> | ||
{% endfor %} | ||
</td> | ||
</tr> | ||
</table> | ||
<p class="input-append"> | ||
<input type="text" placeholder="rename that public key"><button | ||
class="btn"><i class="icon-pencil"></i>update</button> | ||
</p> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p class="well form-inline"> | ||
<input id="key_name" placeholder="Where will this key be used?"> | ||
<button class="btn" id="key_add">Create</button> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="modal fade" id="modal_del_entity"> | ||
<div class="modal-header"> | ||
<a class="close" data-dismiss="modal">×</a> | ||
<h3>Are you sure?</h3> | ||
</div> | ||
<div class="modal-body"> | ||
<p> | ||
Public key <strong></strong> will be deleted. Software using this | ||
key will no longer be able to access to your pixelpost information. | ||
</p> | ||
</div> | ||
<div class="modal-footer"> | ||
<a href="#" class="btn" data-dismiss="modal">Cancel</a> | ||
<a href="#" class="btn btn-danger btn-primary">Delete</a> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<form id="form-account" method="post" accept-charset="utf-8" class="form-horizontal"> | ||
<fieldset> | ||
<legend>Update account settings</legend> | ||
{% if form.flag_success %} | ||
<p class="alert alert-success fade in"> | ||
<a class="close" data-dismiss="alert">×</a> | ||
Updated ! | ||
</p> | ||
{% endif %} | ||
{% if form.flag_reconnect %} | ||
<p class="alert alert-warning fade in"> | ||
<a class="close" data-dismiss="alert">×</a> | ||
You need to reconnect on next page. | ||
</p> | ||
{% endif %} | ||
<div class="control-group"> | ||
<label class="control-label" for="name">Username:</label> | ||
<div class="controls"> | ||
<input id="name" name="name" value="{{ user.name }}" placeholder="username" required> | ||
</div> | ||
</div> | ||
<div class="control-group"> | ||
<label class="control-label" for="email">Email:</label> | ||
<div class="controls"> | ||
<input type="email" id="email" name="email" value="{{ user.email }}" placeholder="user@example.com" required> | ||
</div> | ||
</div> | ||
<div class="control-group"> | ||
<label class="control-label" for="password">Password:</label> | ||
<div class="controls"> | ||
<input type="password" id="password" name="password" placeholder="keep it empty will not change it"> | ||
</div> | ||
</div> | ||
<div class="form-actions"> | ||
<button class="btn btn-primary" type="submit">Update</button> | ||
<button class="btn" type="reset">Reset</button> | ||
</div> | ||
</fieldset> | ||
</form> |
Oops, something went wrong.