public function registrationAction() { $request = $this->getRequest(); if (JO_Session::get('user_id')) { $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit')); } $this->view->usersCount = Model_Users::countUsers(); $this->view->itemsCount = Model_Items::countItems(); $this->getLayout()->meta_title = $this->translate('Registration'); $this->getLayout()->meta_description = $this->translate('Registration'); $captcha = new Model_Recaptcha(); $captcha->publicKey = JO_Registry::get('recaptcha_public_key'); $captcha->privateKey = JO_Registry::get('recaptcha_private_key'); if (JO_Session::issetKey('data')) { if (JO_Session::issetKey('msg_error')) { $this->view->msg_error = JO_Session::get('msg_error'); JO_Session::clear('msg_error'); } elseif (JO_Session::issetKey('error')) { $this->view->error = JO_Session::get('error'); JO_Session::clear('error'); } $this->view->user = JO_Session::get('data'); JO_Session::clear('data'); } if (JO_Session::issetKey('fb_data')) { $this->view->user = JO_Session::get('fb_data'); JO_Session::clear('fb_data'); } if ($request->isPost()) { $captcha->checkCaptcha(); $error = array(); $this->view->firstname = trim($request->getPost('firstname')); $this->view->lastname = trim($request->getPost('lastname')); $this->view->email = trim($request->getPost('email')); $this->view->email_confirm = trim($request->getPost('email_confirm')); $this->view->username = trim($request->getPost('username')); $this->view->password = trim($this->getRequest()->getPost('password')); $this->view->password_confirm = trim($request->getPost('password_confirm')); if (empty($this->view->firstname)) { $error['efirstname'] = $this->translate('You must type your first name'); } if (empty($this->view->lastname)) { $error['elastname'] = $this->translate('You must type your last name'); } if (empty($this->view->email)) { $error['eemail'] = $this->translate('You must type your email'); } elseif (!Model_Users::ValidMail($this->view->email)) { $error['eemail'] = $this->translate('You must type valid email'); } elseif (Model_Users::isExistEmail($this->view->email)) { $error['eemail'] = $this->translate('The email you have entered is already in our database'); } if (empty($this->view->email_confirm)) { $error['eemail_confirm'] = $this->translate('You must retype your email'); } elseif ($this->view->email_confirm != $this->view->email) { $error['eemail_confirm'] = $this->translate('The email adresses you have entered, does not match'); } $methodNames = array(); if (version_compare(PHP_VERSION, '5.2.6') === -1) { $class = new ReflectionObject($this); $classMethods = $class->getMethods(); foreach ($classMethods as $method) { $methodNames[] = $method->getName(); } } else { $methodNames = get_class_methods($this); } $temp_methodNames = array(); foreach ($methodNames as $methodName) { if (preg_match('/^([\\w]{1,})Action$/i', $methodName, $match)) { $temp_methodNames[] = $match[1]; } } $temp_methodNames = array_change_key_case($temp_methodNames, CASE_LOWER); if (empty($this->view->username)) { $error['eusername'] = $this->translate('You must type your username'); } elseif (!preg_match('/^[a-zA-Z0-9_]+$/i', $this->view->username)) { $error['eusername'] = $this->translate('The username you have entered is not valid'); } elseif (Model_Users::isExistUsername($this->view->username)) { $error['eusername'] = $this->translate('There is already registration with that username'); } elseif (in_array(strtolower($this->view->username), $temp_methodNames)) { $error['eusername'] = $this->translate('This username can not be registered'); } if (empty($this->view->password)) { $error['epassword'] = $this->translate('You must type your password'); } if (empty($this->view->password_confirm)) { $error['epassword_confirm'] = $this->translate('You must retype your password'); } elseif ($this->view->password_confirm != $this->view->password) { $error['epassword_confirm'] = $this->translate('The passwords you have entered does not match'); } if ($captcha->getError()) { $error['ecaptcha'] = $this->translate('You must fill correct captcha'); } if (!$request->getPost('terms')) { $error['eterms'] = $this->translate('You must agree with the terms'); } if (!count($error)) { $activationKey = md5(rand(0, 10000) . date('HisdmY') . rand(0, 10000)); if (!is_null(JO_Cookie::get('referral'))) { $referal = Model_Users::getUser(JO_Cookie::get('referral')); JO_Cookie::delete('referral'); } Model_Users::register(array('username' => $this->view->username, 'password' => md5(md5($this->view->password)), 'email' => $this->view->email, 'firstname' => $this->view->firstname, 'lastname' => $this->view->lastname, 'activate_key' => $activationKey, 'referal_id' => isset($referal['user_id']) ? $referal['user_id'] : 0, 'fb_id' => $request->issetPost('fb_id') ? $request->getPost('fb_id') : 0)); if ($request->getPost('subscribed')) { Model_Bulletin::add(array('fname' => $this->view->firstname, 'lname' => $this->view->lastname, 'email' => $this->view->email)); } $is_mail_smtp = JO_Registry::forceGet('config_mail_smtp'); $not_template = Model_Notification::getNotification('registration'); $mail = new JO_Mail(); if ($is_mail_smtp) { $mail->setSMTPParams(JO_Registry::forceGet('config_mail_smtp_host'), JO_Registry::forceGet('config_mail_smtp_port'), JO_Registry::forceGet('config_mail_smtp_user'), JO_Registry::forceGet('config_mail_smtp_password')); } $domain = $request->getDomain(); $mail->setFrom('noreply@' . $domain); $mail->setReturnPath('noreply@' . $domain); $mail->setSubject($this->translate('Email activation') . ' ' . JO_Registry::get('store_meta_title')); if ($not_template) { $title = $not_template['title']; $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8'); $html = str_replace('{USERNAME}', $this->view->username, $html); $html = str_replace('{URL}', WM_Router::create($request->getBaseUrl() . '?controller=users&action=login&command=activate&user='******'&key=' . $activationKey), $html); } else { $link = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login&command=activate&user='******'&key=' . $activationKey); $html = nl2br('To activate your profile in ' . JO_Registry::get('meta_title') . ', please click the following link: <a href="' . $link . '">' . $link . '</a>'); } $mail->setHTML($html); $result = (int) $mail->send(array($this->view->email), $is_mail_smtp ? 'smtp' : 'mail'); if ($result) { $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=verify')); } else { JO_Session::set('msg_error', $this->translate('The email was not send. Please try again later')); } } else { JO_Session::set('error', $error); } $request->setParams('username', $this->view->username); JO_Session::set('data', $request->getParams()); $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=registration')); } $this->view->recaptcha = $captcha->getCaptcha(); $this->view->terms = Model_Pages::get(JO_Registry::forceGet('page_terms')); $this->view->checkAvaibility = WM_Router::create($request->getBaseUrl() . '?controller=users&action=checkAvaibility'); if ($this->view->terms) { $this->view->terms['text'] = html_entity_decode($this->view->terms['text'], ENT_QUOTES, 'utf-8'); } $facebook = new WM_Facebook_Api(array('appId' => JO_Registry::forceGet('facebook_appid'), 'secret' => JO_Registry::forceGet('facebook_secret'))); $this->view->facebook_link = $facebook->getLoginUrl(array('redirect_uri' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=callback_facebook'), 'req_perms' => JO_Registry::forceGet('facebook_req_perms'), 'scope' => JO_Registry::forceGet('facebook_req_perms'))); $this->view->children = array(); $this->view->children['header_part'] = 'layout/header_part'; $this->view->children['footer_part'] = 'layout/footer_part'; }
public function _initRef() { $request = JO_Request::getInstance(); if ($request->getRequest('ref')) { $db = JO_Db::getDefaultAdapter(); if (is_null(JO_Cookie::get('referral'))) { $query = $db->select()->from('users')->where('username = ?', $request->getRequest('ref'))->limit(1, 0); $ref_user = $db->fetchRow($query); if ($ref_user) { JO_Cookie::set('referral', $ref_user['user_id'], 2628000); $db->insert('users_referals_count', array('user_id' => 0, 'referal_id' => (int) $ref_user['user_id'], 'datetime' => new JO_Db_Expr('NOW()'), 'order_type' => 'gast')); } else { JO_Cookie::delete('referral'); } } else { $cookie = JO_Cookie::get('referral'); JO_Cookie::set('referral', $cookie, 2628000); } } }