예제 #1
0
파일: account.php 프로젝트: rratcliffe/fsen
    public function delete_account()
    {
        $delete_intent = $this->post('deleteIntent');
        $user_name = $this->post('userName');
        $hashed_passwd = $this->post('hashedPasswd');
        if (!fse_try_to_login()) {
            header("location:/fse_login");
        }
        if ($delete_intent != 'delete my account') {
            $this->set('error', t('You did not confirm your intent!'));
            return;
        }
        if ($_SESSION['FSEInfo']['user_name'] != $user_name) {
            $this->set('error', t('Wrong username!'));
            return;
        }
        if ($_SESSION['FSEInfo']['hashed_passwd'] != $hashed_passwd) {
            $this->set('error', t('Wrong password!'));
            return;
        }
        $db = Loader::db();
        $projects = $db->getAll('SELECT project_id, doc_lang FROM fsen_projects WHERE fse_id=?', array($_SESSION['FSEInfo']['fse_id']));
        foreach ($projects as $p) {
            $db->Execute("DELETE FROM fsen_projects WHERE project_id=?", array($p['project_id']));
            /* delete project pages */
            $page = Page::getByPath(ProjectInfo::assemblePath($p['project_id'], 'home'));
            if ($page->getCollectionID() > 0) {
                $page->delete();
            }
            ProjectInfo::onDeleteProject($p['project_id']);
        }
        if (preg_match("/^zh/i", $_SESSION['FSEInfo']['def_locale'])) {
            $doc_lang = 'zh';
        } else {
            $doc_lang = 'en';
        }
        ProjectInfo::deleteProjectDocPart(SYSTEM_PROJECT_SHORTNAME . '-' . $doc_lang, 'document', 'blog', $user_name);
        $page = Page::getByPath("/{$doc_lang}/engineer/{$user_name}");
        if ($page->getCollectionID() > 0) {
            $page->delete();
        }
        $db->query("DELETE FROM fse_basic_profiles WHERE user_name=?", array($user_name));
        $nick_name = $_SESSION['FSEInfo']['nick_name'];
        $email_box = $_SESSION['FSEInfo']['email_box'];
        $url_register = BASE_URL . '/fse_register';
        $mail_subject = t('[FSEN] Your account have been deleted!');
        $mail_body = t('Dear %s,

We have deleted your account at FSEN (FullStackEngineer.Net)!

We welcome you to sign up a new account at FSEN at any time:

	%s

Good luck and regards,
Your friends at FSEN', $nick_name, $url_register);
        $mh = Loader::helper('mail');
        $mh->setSubject($mail_subject);
        $mh->setBody($mail_body);
        $mh->from(EMAIL_DEFAULT_FROM_ADDRESS, EMAIL_DEFAULT_FROM_NAME);
        if (defined('EMAIL_DEFAULT_BCC_ADDRESS')) {
            $mh->bcc(EMAIL_DEFAULT_BCC_ADDRESS, EMAIL_DEFAULT_BCC_NAME);
        }
        $mh->to($email_box, $nick_name);
        $mh->sendMail();
        unset($_SESSION['FSEInfo']);
        setcookie("FSEID", null, time() - 3600 * 24 * 365, DIR_REL . '/');
        setcookie("HashedPasswd", null, time() - 3600 * 24 * 365, DIR_REL . '/');
        header("location:/");
        exit(0);
    }