root/trunk/actions/login-icas.action.php

Revision 1, 3.6 KB (checked in by anonymous, 7 years ago)

initial import

Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:   
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25if( $_POST['login'] && $_POST['md5_passwd'])
26{
27    $rpc_login = new Logikse($dsn_logikse);
28    $res = $rpc_login->check(stripslashes($_POST['login']), $_POST['md5_passwd']);
29    if(Logikse::isError($res))
30    {
31        switch($res->getErrorNo())
32        {
33            case LOGIN_NOTSUBSCRIBED:
34                $_SESSION['subscribe']['login'] = stripslashes($_POST['login']);
35                $_SESSION['subscribe']['passwd'] = md5(stripslashes($_POST['md5_passwd']));
36                header('location: /pub/subscribe');
37                break;
38
39            default:
40                if($res->getMessage())
41                    $_SESSION['error']['msg'] = $res->getMessage();
42                else
43                    $_SESSION['error']['msg'] = 'Unknow error #'.$res->getErrorNo();
44                header('location: /pub');
45        }
46    }
47    else
48    {
49        $user =& $db->getRow('SELECT id, login, fname, lname, nick, status FROM user WHERE login=?', array($res['login']));
50        if( !DB::isError($user) )
51        {
52            session_destroy();
53
54            session_set_save_handler ('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
55            session_start();
56
57            $_SESSION['my_ip'] = $_SERVER['REMOTE_ADDR'];
58            srand(time());
59            $SecID = md5(rand(999,10000000));
60            setcookie('SecID', $SecID, time()+31536000, '/');
61            $_SESSION['SecID'] = $SecID;
62            $_SESSION['status'] = 'member';
63            $_SESSION['my_id'] = $user['id'];
64            $_SESSION['my_login'] = $user['login'];
65            $_SESSION['my_fname'] = $user['fname'];
66            $_SESSION['my_lname'] = $user['lname'];
67            $_SESSION['my_nick'] = $user['nick'];
68            if($user['status']=='jail')
69            {
70                session_unset();
71                session_destroy();
72                header('Location: /pub/join');
73                exit();
74            }
75            $_SESSION['my_status'] = $user['status'];
76            $_SESSION['my_photo'] = build_image_url($user['id']);
77
78            $cache_user = get_cache_user_info($user['id'], 'country, friends_id, communities_id');
79            $_SESSION['my_country'] = $cache_user['country'];
80            $_SESSION['my_friends_id'] = $cache_user['friends_id'];
81            $_SESSION['my_communities_id'] = $cache_user['communities_id'];
82
83            $_SESSION['nb_new_messages'] = $db->getOne('SELECT COUNT(id_mess) FROM message WHERE id=? AND flag=? AND box=?', array($_SESSION['my_id'], 'new', 'inbox'));
84            $_SESSION['nb_new_messages_timestamp'] = time();
85
86            $_SESSION['lastaction_timestamp'] = 1;
87
88            $db->query('UPDATE user SET last_visite=?, ip=? WHERE id=?', array(time(), $_SERVER['REMOTE_ADDR'], $_SESSION['my_id'] )) ;
89            if($_POST['url'])
90                header('Location: '.urldecode($_POST['url']));
91            else
92                header('Location: /my');
93        }
94        else
95        {
96            $_SESSION['error']['msg'] = "Wrong login";
97            header('Location: /pub'); // Wrong login / pass
98        }
99    }
100}
101else
102{
103    $_SESSION['error']['msg'] = "No login";
104    header('Location: /pub'); // no login/pass
105}
106?>
Note: See TracBrowser for help on using the browser.