Added Visitors

This commit is contained in:
Miroslav Šedivý 2017-09-25 20:43:27 +02:00
parent 562f968285
commit 5ca35ab5bc
5 changed files with 46 additions and 15 deletions

View file

@ -310,7 +310,7 @@ class Post
"SELECT `id`, `text`, `feeling`, `persons`, `location`, `privacy`, `content_type`, `content`, DATE_FORMAT(`posts`.`datetime`,'%d %b %Y %H:%i') AS `datetime` ".
"FROM `posts` ".
"WHERE ".
(!User::is_logged_in() ? "`privacy` = 'public' AND " : "").
(!User::is_logged_in() ? (User::is_visitor() ? "`privacy` IN ('public', 'friends') AND " : "`privacy` = 'public' AND ") : "").
($until ? "`posts`.`datetime` < DATE_ADD('{$until}', INTERVAL +1 MONTH) AND " : "").
($id ? "`id` = {$id} AND " : "").
($tag ? "`plain_text` LIKE '%{$tag}%' AND " : "").
@ -331,6 +331,6 @@ class Post
}
public static function handshake($r){
return ["logged_in" => User::is_logged_in()];
return ["logged_in" => User::is_logged_in(), "is_visitor" => User::is_visitor()];
}
}

View file

@ -4,6 +4,14 @@ class user
{
const SESSION_NAME = "logged_in";
public static function is_visitor(){
if(!Config::get_safe("force_login", false)){
return true;
}
return !empty($_SESSION[User::SESSION_NAME]) && $_SESSION[User::SESSION_NAME] == 'visitor';
}
public static function is_logged_in(){
if(!Config::get_safe("force_login", false)){
return true;
@ -23,9 +31,14 @@ class user
if(Config::get("nick") == $nick && Config::get_safe("pass", "") == $pass){
$_SESSION[User::SESSION_NAME] = md5($nick.$pass);
return true;
return ["logged_in" => true, "is_visitor" => false];
}
if(($visitors = Config::get_safe("visitor", [])) && !empty($visitors) && isset($visitors[$nick]) && $visitors[$nick] === $pass){
$_SESSION[User::SESSION_NAME] = 'visitor';
return ["logged_in" => false, "is_visitor" => true];
}
Log::put("login_fails", $nick);
throw new Exception(__("The nick or password is incorrect."));
}
@ -35,7 +48,7 @@ class user
throw new Exception(__("You can't log out. There is no account."));
}
if(!self::is_logged_in()){
if(!self::is_logged_in() && !self::is_visitor()){
throw new Exception(__("You are not even logged in."));
}

View file

@ -23,13 +23,18 @@ highlight = true
;styles[] = static/styles/custom2.css
;scripts = static/styles/scripts.css
[bbcode]
;bbtags[quote] = "<quote>{param}</quote>"
[login]
[admin]
force_login = true
nick = demo
pass = demo
[visitors]
;visitor[user] = pass
;visitor[user] = pass
[system]
system_name = blog
version = 1.05

View file

@ -290,7 +290,7 @@ if(!empty($scripts)){
<!-- Pirvacy Settings -->
<ul class="b_dropdown privacy_settings">
<li><a class="set" data-val="public"><i class="public"></i><?php echo __("Public"); ?></a></li>
<!--<li><a class="set" data-val="friends"><i class="friends"></i><?php echo __("Friends"); ?></a></li>-->
<li><a class="set" data-val="friends"><i class="friends"></i><?php echo __("Friends"); ?></a></li>
<li><a class="set" data-val="private"><i class="private"></i><?php echo __("Only me"); ?></a></li>
</ul>
</div>

View file

@ -156,7 +156,8 @@ var cnt_funcs = {
// Login function
var login = {
is: false,
visitor: false,
// Logout button
logout_btn: function(name){
var btn = $('#prepared .logout_btn').clone();
@ -174,11 +175,15 @@ var login = {
$("body").error_msg(data.msg);
return ;
}
// Remove new post input
if(login.is){
new_post.remove();
}
// Is not logged in anymore
login.is = false;
// Remove new post input
new_post.remove();
login.visitor = false;
// Remove logout button
btn.remove();
// Load first posts
@ -231,9 +236,13 @@ var login = {
}
// Now is logged in
login.is = true;
login.is = data.logged_in;
login.visitor = data.is_visitor;
// Logged in user can add post
new_post.create();
if(login.is){
new_post.create();
}
// Remove login button
btn.remove();
// Load first posts
@ -272,11 +281,15 @@ var login = {
// Check if is logged in
login.is = data.logged_in;
if(!login.is){
login.visitor = data.is_visitor;
if(!login.is && !login.visitor){
login.login_btn();
} else {
login.logout_btn();
// Logged in user can add post
}
// Logged in user can add post
if(login.is){
new_post.create();
}