namespace Iekadou\Webapp;

require_once "../inc/include.php";
try {
    $errors = array();
    $identification = isset($_POST['identification']) ? htmlspecialchars($_POST['identification']) : false;
    $login_user = false;
    $User = new User();
    if ($identification == false || $identification == '') {
        $errors[] = "identification";
    } else {
        $login_user = $User->get_by(array(array('username', '=', $identification)));
        if ($login_user == false) {
            $login_user = $User->get_by(array(array('email', '=', $identification)));
        }
        if ($login_user == false) {
            $errors[] = "identification";
        }
    }
    if (!empty($errors)) {
        throw new ValidationError($errors);
    } else {
        $login_user->send_new_password();
        echo '{"url": "' . UrlsPy::get_url('home') . '"}';
        die;
    }
} catch (ValidationError $e) {
    echo $e->stringify();
    die;
}
Example #2
0
 public function send_activation_email()
 {
     $this->generate_activation_key();
     $this->save();
     $subject = Translation::translate('Your account at {{ SITE_NAME }}', array('{{ SITE_NAME }}' => SITE_NAME));
     $content = Translation::translate("Hey {{ username }},\nyou can activate your account by clicking the following link:\nhttps://{{ DOMAIN }}{{ activate_url }}\n\nHave fun on {{ SITE_NAME }}", array('{{ username }}' => $this->get_username(), '{{ activation_key }}' => $this->get_activation_key(), '{{ SITE_NAME }}' => SITE_NAME, '{{ DOMAIN }}' => DOMAIN, '{{ activate_url }}' => UrlsPy::get_url('activate', array($this->get_activation_key()))));
     $header = 'From: noreply@quickies.io';
     if (mail($this->get_email(), $subject, $content, $header)) {
         return $this;
     } else {
         throw new ValidationError(array());
     }
 }
Example #3
0
namespace Iekadou\Webapp;

require_once "../inc/include.php";
$User = new User();
try {
    $User->interpret_user($_POST, $_FILES);
} catch (ValidationError $e) {
    echo $e->stringify();
    die;
}
try {
    $User->create();
} catch (ValidationError $e) {
    echo $e->stringify();
    die;
}
try {
    $User->send_activation_email();
} catch (ValidationError $e) {
    echo $e->stringify();
    die;
}
try {
    Account::login($User, $password = null);
} catch (ValidationError $e) {
    echo $e->stringify();
    die;
}
echo '{"url": "' . UrlsPy::get_url('account') . '"}';