Permalink
Browse files

Fix login, finish favorites, pretty errors

  • Loading branch information...
1 parent 871bea0 commit 73dea80d7ea41ac479ac113cc147eea45df9fdd8 @jcubic jcubic committed Nov 27, 2012
View
Oops, something went wrong.
View
@@ -104,22 +104,25 @@
));
$app->error(function($exception) {
- return full_exception_string($exception, "<br/>");
+ //return full_exception_string($exception, "<br/>");
global $app;
return new Template('main', function() use ($exception) {
- return array('content' => new Template('exception', function() use ($exception) {
- global $app;
- return array(
- 'name' => get_class($exception),
- 'message' => $exception->getMessage(),
- 'file' => str_replace($app->config->root_directory,
- '',
- $exception->getFile()),
- 'line' => $exception->getLine(),
- 'trace' => implode("\n", get_trace($exception)) //->getTraceAsString()
- );
- }));
+ return array(
+ 'login-dialog' => new Template('login-dialog', null),
+ 'content' => new Template('exception', function() use ($exception) {
+ global $app;
+ return array(
+ 'name' => get_class($exception),
+ 'message' => $exception->getMessage(),
+ 'file' => str_replace($app->config->root_directory,
+ '',
+ $exception->getFile()),
+ 'line' => $exception->getLine(),
+ 'trace' => implode("\n", get_trace($exception)) //->getTraceAsString()
+ );
+ })
+ );
});
});
@@ -138,22 +141,23 @@
$redirect = isset($app->GET->redirect) ? $app->GET->redirect : $app->config->root;
// TODO: redirect don't work
try {
- $app->login($_POST['login'], $_POST['password']);
- $app->redirect($redirect);
- return;
+ //$app->redirect($redirect);
+ //return;
+ return $app->login($_POST['login'], $_POST['password']) === NULL ? 'null' : 'false';
} catch (LoginException $e) {
$error = $e->getMessage();
}
}
return new Template('main', function() use ($error) {
return array(
+ 'login-dialog' => new Template('login-dialog', null),
'content' => array(new Template('login', function() use ($error) {
global $app;
return array(
// fill login on second attempt
'login' => isset($_POST['login']) ? $_POST['login'] : '',
'error' => $error,
- 'redirect' => $app->GET->redirect
+ 'redirect' => isset($app->GET->redirect) ? $app->GET->redirect : ''
);
}))
);
View
@@ -48,7 +48,7 @@ function favorite($clipart) {
throw new Exception("You can't favorite a clipart if you are not logged in");
} else {
$clipart = intval($clipart);
- $id = $this->config->id;
+ $id = $this->config->userid;
$query = "INSERT INTO openclipart_favorites VALUES($clipart, $id, NOW())";
return $this->db->query($query);
}
@@ -59,7 +59,7 @@ function unfavorite($clipart) {
throw new Exception("You can't favorite a clipart if you are not logged in");
} else {
$clipart = intval($clipart);
- $id = $this->config->id;
+ $id = $this->config->userid;
$query = "DELETE FROM openclipart_favorites WHERE clipart = '$clipart' AND user = '$id'";
return $this->db->query($query);
}
@@ -72,7 +72,7 @@ function list_clipart($where, $order_by) {
$nsfw = '';
}
if ($this->is_logged()) {
- $fav_check = $this->get_user_id() . ' in '.
+ $fav_check = $this->config->userid . ' in '.
'(SELECT user FROM openclipart_favorites'.
' WHERE openclipart_clipart.id = clipart)';
} else {
View
@@ -45,12 +45,12 @@ function create_group($group) {
function add_to_group($user, $group) {
//
}
+ // act as other user
function disguise($id) {
$this->system->__authorize("id = " . intval($id));
}
}
-
class System extends Slim {
public $groups;
private $original_config;
@@ -89,6 +89,8 @@ function __construct($settings) {
throw new SystemException("Invalid UserID in Session");
}
}
+ // debug
+ // $settings['system_warnings'][] = 'hello';
if (isset($_GET['token'])) {
$token = $this->db->escape($_GET['token']);
try {
@@ -183,7 +185,6 @@ function user_exist($username) {
// ---------------------------------------------------------------------------------
function login($username, $password) {
- $table = $this->config->db_prefix . '_users';
$username = $this->db->escape($username);
$password = $this->db->escape($password);
$where = "username = '$username'";// AND password = md5(md5('$password'))";
@@ -251,9 +252,10 @@ function user_by_name($username) {
}
// ---------------------------------------------------------------------------------
// SystemFunctions class need this function for disguise php have not friend
+ // param $where is part of sql that will authorize
function __authorize($where = null) {
if ($where == null || $where == '') {
- throw new Exception("where argument to authorize private method " .
+ throw new Exception("where argument to __authorize private method " .
"can't be null or empty");
}
$table = $this->db_prefix . '_users';
@@ -344,7 +346,7 @@ function track() {
// ---------------------------------------------------------------------------------
function is_logged() {
- return isset($this->config->id) && is_numeric($this->config->id);
+ return isset($this->config->userid) && is_numeric($this->config->userid);
}
// ---------------------------------------------------------------------------------
View
@@ -1,7 +1,10 @@
<?php
class main {
-
+ function test() {
+ global $app;
+ return $app->is_logged();
+ }
function favorite($clipart) {
global $app;
return $app->favorite(intval($clipart));
View
@@ -256,9 +256,14 @@ $(function() {
var img = $('#viewimg img, #shutterstock img').bg();
rpc({url: '/rpc/main', error: function(e) {
+ if (e.error) {
+ alert(e.error.message + ' file ' + e.error.file + ' at ' + e.error.at + '\n' +
+ e.error.line);
+ } else {
alert(e.message || e);
+ }
}})(function(main) {
-
+ window.main = main;
function editable() {
var tag_list = $('.tags ul');
var tags = tag_list.find('li').detach();
@@ -358,7 +363,7 @@ $(function() {
$('.overlay').click(function() {
$(this).parent().fadeOut();
});
- $('#login-popup-window #login-submit').click(function() {
+ $('#login-dialog #popup-window #login-submit').click(function() {
var login = $('#login').val();
var pass = $('#password').val();
main.login(login, pass)(function(ret) {
@@ -388,16 +393,19 @@ $(function() {
var thumb = self.parents('.thumbnail');
var clipart = thumb.data('id');
// !!+ string "0" or "1" to int and then to boolean
- if (!!+thumb.data('favorite')) {
+ //if (!!+thumb.data('favorite')) {
+ if (!thumb.hasClass('can_fav')) {
main.unfavorite(clipart)(function(removed) {
if (removed) {
self.text(self.text()-1);
+ thumb.addClass('can_fav');
}
});
} else {
main.favorite(clipart)(function(added) {
if (added) {
self.text(+self.text()+1);
+ thumb.removeClass('can_fav');
}
});
}
@@ -409,5 +417,4 @@ $(function() {
Picatcha.PUBLIC_KEY = 'qjSWPO6lV1MO_uJUDq2xmWlleGAUVQfRiul52kYm';
Picatcha.create('picatcha');
-
});
@@ -1,5 +1,5 @@
{{#clipart_list}}
-<div class="thumbnail" data-id="{{id}}" data-favorite="{{user_fav}}">
+<div class="thumbnail{{^user_fav}} can_fav{{/user_fav}}" data-id="{{id}}" data-favorite="{{user_fav}}">
<a href="/clipart/{{id}}/{{link}}{{forward_query}}" title="{{title}}">
<span class="thumbnail-image">
<img src="/image/100/{{username}}/{{filename_png}}{{forward_query}}">
@@ -1,4 +1,4 @@
-<div id="login-form">
+<div id="login-form" class="grid_16">
<h2>Login</h2>
<p>(*Fields are case sensitive)</p>
{{#error}}
@@ -22,4 +22,5 @@
<a href="/register">Register</a>
</div>
</form>
+ {{debug}}
</div>
@@ -11,7 +11,7 @@
</head>
<body>
{{! jquery added if editable (NOTE: rpc have it's own check)}}
- <div id="container" class="container_24 {{#editable}} editable{{/editable}}{{#userid}} logged{{/userid}}{{#class}} {{class}}{{/class}}-template">
+ <div id="container" class="container_24 {{#editable}} editable{{/editable}}{{#userid}} logged{{/userid}}{{#class}} {{class}}-template{{/class}}">
<a href="https://github.com//openclipart"><img style="position: absolute; top: 0px; right: 0px; border: 0; opacity: 0.5; z-index: 100;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<div id="left" class="grid_8 alpha omega">
<div id="main-navigation" class="grid_8 alpha omega">
@@ -52,7 +52,7 @@
</div><!--end main-navigation-->
<div class="sidebar-block grid_8">
-
+
<div class="accordion-container">
<input id="ac-sidebar-1" class="hidden" name="accordion-sidebar" type="checkbox" />
<label for="ac-sidebar-1">Username</label>
@@ -67,10 +67,9 @@
</div>
<div class="ads sidebar-ad">
- <div><a href="/why-the-ads">why the ads?</a></div>
- <img src="img/adsense_185665_adformat-text_200x200_en.png" />
- </div>
-
+ <div><a href="/why-the-ads">why the ads?</a></div>
+ <img src="img/adsense_185665_adformat-text_200x200_en.png" />
+ </div>
</div>
{{> social-box}}
@@ -89,9 +88,9 @@
</div>
<div class="grid_7 ads top-ad">
- <div><a href="/why-the-ads">why the ads?</a></div>
- <a href="#"><img src="img/adsense_185665_adformat-text_234x60_en.png" /></a>
- </div>
+ <div><a href="/why-the-ads">why the ads?</a></div>
+ <a href="#"><img src="img/adsense_185665_adformat-text_234x60_en.png" /></a>
+ </div>
<div id="donation-buttons" class="grid_3">
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FSUSWMQXL8AKS"><img src="img/donation-paypal.png" /></a>
@@ -107,7 +106,7 @@
<div class="wrapper login-menu">
<a href="/profile">profile</a> | <a id="logout" href="/logout">logout</a>
</div>
-
+
<!-- no foreign languages supported yet
<ul>
<li class="active"><a href="#">english</a></li>
@@ -116,24 +115,32 @@
<li><a href="#">french</a></li>
</ul>
-->
-
+
</div><!--end login-register-language-->
{{> login-dialog}}
+ <div class="grid_16">
+ <ul>
+ {{#system_warnings}}
+ <li>{{.}}</li>
+ {{/system_warnings}}
+ </ul>
+ </div>
+
{{> content}}
-
- <div class="grid_16 aplha omega">
- <div class="ads footer-ad">
- <div><a href="/why-the-ads">why the ads?</a></div>
- <img src="img/adsense_185679_adformat-link_468x15_en.png" />
- </div>
- </div>
+
+ <div class="grid_16 aplha omega">
+ <div class="ads footer-ad">
+ <div><a href="/why-the-ads">why the ads?</a></div>
+ <img src="img/adsense_185679_adformat-link_468x15_en.png" />
+ </div>
+ </div>
</div><!--end right-->
<div id="footer" class="grid_24">
-
+
<ul>
<li><em><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FSUSWMQXL8AKS">Donate to Support Hosting + Maintenance</a></em></li>
<li><a href="http://fabricatorz.com/">Fabricatorz 王</a></li>
@@ -154,11 +161,8 @@
<link href="/libs/jquery-ui/jquery-ui-1.8.24.custom.css" rel="stylesheet"/>
<link href="/libs/tag-it/css/jquery.tagit.css" rel="stylesheet"/>
<script src="/libs/tag-it/js/tag-it.js"></script>
- {{^userid}}
- {{! don't load if logged in }}
<script src="http://api.picatcha.com/static/client/picatcha.js" type="text/javascript"></script>
<link href="http://api.picatcha.com/static/client/picatcha.css" type="text/css" rel="stylesheet"/>
- {{/userid}}
<script src="{{root}}/script.js"></script>
</body>
</html>

0 comments on commit 73dea80

Please sign in to comment.