websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 276 (differences)
Author: xbright
Log message: Show private projects in a profile only if the user is the current visitor
Change revision:
<?php
#    This file is a part of CodingTeam. See <http://www.codingteam.net>.
#    Copyright (C) 2007-2009 CodingTeam (See AUTHORS and THANKS for details)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, version 3 only.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
class View {
    private $session, $db, $page, $error, $langlist, $lang;
    public $metatags, $maincontent;
    
    function __construct($session, $db, $page, $error, $langlist, $lang)
    {
        // Variables
        $this->ct_session = $session;
        $this->ct_db = $db;
        $this->page = $page;
        $this->error = $error;
        $this->langlist = $langlist;
        $this->lang = $lang;
 
        // Meta tags
        $this->metatags = array('title' => i18n('Password recovering'));
 
        // Exit if logged
        if ($this->ct_session->isLogged())
            $this->error->displayError(i18n('You cannot recover your password '.
                                            'when you are logged.'), 0);
    }
 
    function showFeed()
    {
    }
 
    function treatForms()
    {
        $this->form_error = 0;
        $this->form_info = 0;
 
        // Clean POST values
        foreach ($_POST as $key => $value)
            if (!is_scalar($value))
                exit('Error.');
 
        if (count($_POST) == 1)
        {
            $email = $this->ct_db->cleanentry($_POST['mail'], TRUE);
 
            $user = getUser($email, $this->ct_db, 'email');
            if ($user)
            {
                $key = $user->getKeyid();
                $text = i18n('This is your personnal key (42 characters) for '.
                             'the second step of password recovering:'."\n".
                             '%(key)s', array('key' => $key));
                $mail = sendmail(i18n('Recovering password: your key'),
                                 $text, $user->getEmail(), $this->ct_db);
                if (!$mail)
                    $this->form_error = i18n('Mail cannot be sended!');
                else
                    $this->form_info = i18n('Please check your mails.');
            }
            else
                $this->form_error = i18n('No user found with this email.');
        }
        elseif (count($_POST) == 3)
        {
            $key = $this->ct_db->cleanentry($_POST['key'], TRUE);
            $password0 = $this->ct_db->cleanentry($_POST['password0'], TRUE);
            $password1 = $this->ct_db->cleanentry($_POST['password1'], TRUE);
        
            if (strlen($key) != 42)
                $this->form_error = i18n('Key length is wrong!');
 
            if ($password0 != $password1)
                $this->form_error = i18n('Please confirm your password!');
 
            if (!$this->form_error)
            {
                $user = getUser($key, $this->ct_db, 'keyid');
                $classadm = getClass('project.admins', $this->ct_db);
                $classprj = getClass('projects.projects', $this->ct_db);
 
                if ($user)
                {
                    $escn = escapeshellarg($user->getNickname());
                    $escp = escapeshellarg($password0);
                    exec(escapeshellcmd('htpasswd -nbm '.$escn.' '.$escp),
                                                                   $output);
                    $line = explode(':', $output[0]);
 
                    $user->setApache_password($line[1]);
 
                    foreach (array('projects', 'projects_admins') as $type)
                    {
                        $projects = $classadm->getAdmins($user->getId(),
                                                         'user', $type);
 
                        foreach ($projects as $project)
                        {
                            if (isset($project['projectid']))
                                $id = $project['projectid'];
                            else
                                $id = $project['id'];
 
                            $classprj->load($id);
                            $dbname = $classprj->getDbname(); 
 
                            $classsvnadm = getClass('project.svnadmin', $dbname); 
                            $classsvnadm->deleteUser($user->getNickname());
                            $classsvnadm->addUser($user->getNickname(), $line[1]);
 
                            $classprj->unload();
                        }
                    }
 
                    $user->setPassword(md5($password0));
                    
                    $this->ct_session->login($user->getNickname(),
                                             $password0, 0);
                    Header('Location: '.CT_BASEURL.'index');
                }
                else
                    $this->form_error = i18n('No user found with this key.');
            }
        }
    }
 
    function constructView()
    {
        $construct = array();
        $construct['__tpl__'] = 'password.tpl';
 
        $construct['form_error'] = $this->form_error;
        $construct['form_info'] = $this->form_info;
 
        return $construct;
    }
}
?>