Esempio n. 1
0
require_once '../core/init.php';
if (Input::exists()) {
    if (Token::check(Input::get('token'))) {
        $validate = new Validate();
        $profile_pic_check = $validate->ImageCheck(Input::get('profile_pic'));
        $email = $validate->email(Input::get('email'));
        //make sure $validation is the last validation check because it makes sure there are no errors in total(including image errors.)
        $validation = $validate->check($_POST, array('username' => ['fieldname' => 'Username', 'required' => true, 'min' => 3, 'max' => 20, 'unique' => 'users', 'contains' => 'alnum(m:letters)'], 'password' => ['fieldname' => 'Password', 'required' => true, 'min' => 6], 'name' => ['fieldname' => 'Name', 'required' => true, 'min' => 2, 'max' => 50], 'email' => ['fieldname' => 'Email', 'min' => 3, 'max' => 320, 'unique' => 'users']));
        if ($validation->passed()) {
            if ($profile_pic_check === false) {
                $profilePicDest = 'images/default_profile_pic.jpg';
            } else {
                $image = new ImageManipulation(Input::get('profile_pic'));
                $image->moveTo('images/uploads/');
                $profilePicDest = $image->getNewDest();
            }
            $user = new User();
            $salt = Hash::salt(32);
            $email_code = md5(Input::get('username') . microtime());
            try {
                $user->create(['username' => Input::get('username'), 'password' => Hash::make(Input::get('password'), $salt), 'salt' => $salt, 'fullname' => strip_excess(Input::get('name')), 'email' => $email, 'profile_pic' => $profilePicDest]);
                /*
                 * TODO: Email Activation Up and Running. V(1.0)
                 * $mail = new Email;
                 * $mail->sendGmailActivation(BASE_URL . 'activate/' . $email_code );
                 * */
                Session::flash('success', 'You registered successfully!');
                Redirect::to(BASE_URL);
            } catch (Exception $e) {
                die($e->getMessage());