public function registerAction() { $request = $this->getRequest(); $form = new Form_User_Registration(); if ($request->isPost()) { if ($form->isValid($request->getPost())) { $model = new Model_User($form->getValues()); $user_id = $model->save(); $model->setId($user_id); $globalSession = Zend_Registry::get('dlo.session'); $globalSession->user = $model; //Zend_Loader::loadClass('Zend_View'); $view = new Zend_View(); $view->activationLink = "http://DrivingLessonOnline.com/user/verify-email/id/" . $model->getId() . "/guid/" . hash('sha1', $model->getSalt() . $model->getId() . $model->getPassword()) . "/"; $view->setBasePath(APPLICATION_PATH . "/views/"); $mailBodyHtml = $view->render('Templates/Account-Activation-Email.phtml'); //send email verification email before user can start using their account. $mail = new Zend_Mail(); $mail->setBodyHtml($mailBodyHtml); $mail->setFrom('*****@*****.**', 'Registration'); $mail->addTo($model->getEmail(), $model->getDisplayName()); $mail->setSubject($model->getDisplayName() . ' activiate your account for Driving Lesson Online.com'); $mail->send(); //thank user and inform to check their email to enable their account. $this->_redirect('/user/registered'); } } $this->view->form = $form; }
public function configureData() { // Configure top block $top = new Block_Top($this->tpl); $top->configure(); $profile = new Model_User($this->getParameter('login')); $this->tpl->assignVar(array('profile_id' => $profile->getId(), 'profile_login' => $profile->getLogin(), 'profile_avatar' => $profile->getAvatarUri('large'))); // If a user is logged if ($user = Model_User::getLoggedUser()) { // If I'm on my profile if ($user->getId() == $profile->getId()) { $this->tpl->assignSection('private'); } } }
public function fetchByDate($date, Model_User $user) { $select = $this->select(); $select->where('date = ?', $date); $select->where('userId = ?', $user->getId()); return $this->fetchAll($select)->toArray(); }
public function fetchOneByDate($date, Model_User $user) { $select = $this->select($date); $select->where('date = ?', $date); $select->where('userId = ?', $user->getId()); return $this->fetchRow($select); }
public function fetchDaysWithOrWoutGym($date1, $date2, Model_User $user) { $select = "SELECT count(*) as total, date from `" . $this->_name . "`\r\n\t\t\t\t\t\tWHERE userId = " . $user->getId() . " \r\n\t\t\t\t\t\t\tAND\tdate between '" . $date1 . "' and '" . $date2 . "'\r\n\t\t\t\t\t\t\t\tGROUP BY date"; $data = $this->_db->query($select)->fetchAll(); $datesInBetween = array($date1); while (end($datesInBetween) < $date2) { $datesInBetween[] = date('Y-m-d', strtotime(end($datesInBetween) . ' +1 day')); } $final['datesInBetween'] = implode(', ', $datesInBetween); $final['daysWithGym'] = null; foreach ($datesInBetween as $dates) { foreach ($data as $date) { if (in_array($dates, $date)) { $final['daysWithGym'][] = $date['date']; } } if (is_array($final['daysWithGym'])) { if (!in_array($dates, $final['daysWithGym'])) { $final['daysWithoutGym'][] = $dates; } } } $final['countDaysWithGym'] = count($final['daysWithGym']); $final['countDaysWithoutGym'] = count($final['daysWithoutGym']); return $final; }
/** * fetch last logged in date * * @param Model_User $user * @return Ambigous <Zend_Db_Table_Row_Abstract, NULL, unknown> */ public function fetchLastLoggedInInfo(Model_User $user) { $sql = 'SELECT max(id) as maxId FROM ' . $this->_name . ' WHERE `userId` = ' . (int) $user->getId(); $data = $this->_db->fetchRow($sql); $select = $this->select(); $select->where($this->getPrimary() . ' = ?', (int) $data['maxId']); return $this->fetchRow($select); }
/** * * @param Model_User $user * @return int The primary key of the row inserted. OR The number of rows updated. */ public function save(Model_User $user) { $data = array('email' => $user->getEmail(), 'password' => $user->getPassword(), 'firstname' => $user->getFirstName(), 'lastname' => $user->getLastName(), 'role' => $user->getRole(), 'date_modified' => time(), 'email_verified' => $user->getEmailVerified(), 'enabled' => $user->getEnabled(), 'last_login' => $user->getLastLogin(), 'salt' => $user->getSalt()); if (null === ($id = $user->getId())) { unset($data['id']); $data['password'] = hash('ripemd160', $data['password']); $user->setPassword($data['password']); $data['date_created'] = time(); return $this->getDbTable()->insert($data); } else { return $this->getDbTable()->update($data, array('id = ?' => $id)); } }
/** * add a password token and return the token's string * * @param Model_User $user */ public function add(Model_User $user) { // make random token $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double) microtime() * 1000000); $i = 0; $token = ''; while ($i < 40) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $token = $token . $tmp; $i++; } $data = array('token' => $token, 'userId' => $user->getId()); $this->insert($data); return $token; }
/** * calculate macros * * @param string $where * @return array */ public function fetchMacros($date, Model_User $user) { $select = $this->select(); $select->where('date = ?', $date); $select->where('userId = ?', $user->getId()); $data = $this->fetchAll($select)->toArray(); $totalCalories = $mealTotalCalories = $foodTotalCalories = $calories = $protein = $fat = $carbs = $sodium = $sugar = $fiber = $cholesterol = 0; $macros[$date] = array(); if (0 == count($data)) { return false; } foreach ($data as $intake) { if ($intake['mealId']) { $modelMeals = new Model_Meals(); $meal = $modelMeals->fetchMealTotal($intake['mealId']); $calories += $meal['macros']['calories']; $protein += $meal['macros']['protein']; $fat += $meal['macros']['fat']; $sodium += $meal['macros']['sodium']; $cholesterol += $meal['macros']['cholesterol']; $carbs += $meal['macros']['carbs']; $sugar += $meal['macros']['sugar']; $fiber += $meal['macros']['fiber']; $mealTotalCalories += $meal['mealTotalCalories']; } else { $modelFoods = new Model_Foods(); $food = $modelFoods->fetch($intake['foodId'])->toArray(); $calories += $modelFoods->calculateMacros($food['calories'], $food['servingSize'], $intake['servingSize'], '0'); $protein += $modelFoods->calculateMacros($food['protein'], $food['servingSize'], $intake['servingSize'], '0'); $fat += $modelFoods->calculateMacros($food['fat'], $food['servingSize'], $intake['servingSize'], '0'); $sodium += $modelFoods->calculateMacros($food['sodium'], $food['servingSize'], $intake['servingSize'], '0'); $cholesterol += $modelFoods->calculateMacros($food['cholesterol'], $food['servingSize'], $intake['servingSize'], '0'); $carbs += $modelFoods->calculateMacros($food['carbs'], $food['servingSize'], $intake['servingSize'], '0'); $sugar += $modelFoods->calculateMacros($food['sugar'], $food['servingSize'], $intake['servingSize'], '0'); $fiber += $modelFoods->calculateMacros($food['fiber'], $food['servingSize'], $intake['servingSize'], '0'); } } $values = array('calories' => $calories, 'protein' => $protein, 'fat' => $fat, 'sodium' => $sodium, 'cholesterol' => $cholesterol, 'carbs' => $carbs, 'sugar' => $sugar, 'fiber' => $fiber); $macros[$date]['totalCalories'] = array_sum($values); $macros[$date]['foodTotalCalories'] = $macros[$date]['totalCalories'] - $mealTotalCalories; $macros[$date]['mealTotalCalories'] = $mealTotalCalories; $macros[$date]['macros'] = $values; return $macros; }
public static function login($id) { $user = new Model_User($id); $_SESSION['user'] = array('id' => $user->getId(), 'login' => $user->getLogin()); setCookie(Conf::get('SITE_NAME') . '_login', $user->getId() . '-' . $user->getKey(), time() + 86400 * 8, '/'); }
public static function getLoggedUser() { // If a user is connected get its infos if (Tool::isOk($_SESSION['user'])) { return new Model_User($_SESSION['user']['id'], array('login' => $_SESSION['user']['login'])); } else { if (Tool::isOk($_COOKIE[Conf::get('SITE_NAME') . '_login'])) { // If the cookie's data matches if (preg_match('/([0-9]+)-([a-z0-9]{32})/s', $_COOKIE[Conf::get('SITE_NAME') . '_login'], $matches)) { if (Model_User::isKeyValid($matches[1], $matches[2])) { $user = new Model_User($matches[1]); $_SESSION['user'] = array('id' => $user->getId(), 'login' => $user->getLogin()); return $user; } } setcookie(Conf::get('SITE_NAME') . '_login', '', time() - 3600); } } return false; }
public function configureData() { // Configure top block $top = new Block_Top(); $top->configure(); $profile = new Model_User($_GET['login']); Globals::$tpl->assignVar(array('profile_id' => $profile->getId(), 'profile_login' => $profile->getLogin(), 'profile_sex' => $profile->getGender(false), 'profile_avatar' => $profile->getAvatarURL('large'), 'profile_region' => $profile->getZipName(), 'profile_gender' => $profile->getGender())); // Get stats on friends $profileFriendsStats = $profile->getGuessFriendsStats(); // If a user is logged if ($user = Model_User::getLoggedUser()) { // If I'm on my profile if ($user->getId() == $profile->getId()) { Globals::$tpl->assignSection('private'); // Get pending friend requests $pendingFriends = $user->getPendingFriends(); // Assign friends infos foreach ($pendingFriends as $friend) { Globals::$tpl->assignLoopVar('request', array('id' => $friend->getId(), 'login' => $friend->getLogin(), 'avatar' => $friend->getAvatarURL('medium'))); } } } $profileTotalVotes = $profile->getTotalVotes(); Globals::$tpl->assignVar(array('profile_totalVote' => $profileTotalVotes, 'profile_totalPredictionWon' => 0, 'profile_totalPredictionLost' => 0, 'profile_predictionAccuracy' => 0, 'profile_global_distance' => 0, 'profile_friend_distance' => 0)); // Get stats on profil's user guesses according to global votes $profileGGS = $profile->getGuessGlobalStats(); if ($profileGGS['guesses'] != 0) { Globals::$tpl->assignVar(array('profile_totalPredictionWon' => $profileGGS['goodGuesses'], 'profile_totalPredictionLost' => $profileGGS['badGuesses'], 'profile_predictionAccuracy' => round($profileGGS['goodGuesses'] / $profileGGS['guesses'] * 100))); } // List all friends $friends = $profile->getFriends(); foreach ($friends as $friend) { Globals::$tpl->assignLoopVar('friend', array('id' => $friend->getId(), 'login' => $friend->getLogin(), 'avatar_medium' => $friend->getAvatarURL('medium'), 'avatar_small' => $friend->getAvatarURL('small'))); foreach ($profileFriendsStats as $stat) { // Get stats on profil's user gusses if ($friend->getId() == $stat['user']->getId()) { Globals::$tpl->assignLoopVar('friend.stat', array('predictionAccuracy_his' => round($stat['his_guesses'] == 0 ? 0 : $stat['his_goodGuesses'] / $stat['his_guesses'] * 100), 'predictionAccuracy_my' => round($stat['my_guesses'] == 0 ? 0 : $stat['my_goodGuesses'] / $stat['my_guesses'] * 100))); } } } // If profile's user already voted if ($profileTotalVotes != 0) { $totalQuestions = Model_Question::getTotalQuestions(); // Get stats on profil's user votes according to global votes $profileAGS = $profile->getAnswerGlobalStats(); if ($profileAGS['votes'] != 0) { Globals::$tpl->assignVar(array('profile_global_distance' => round(($profileAGS['votes'] - $profileAGS['goodVotes']) / $profileAGS['votes'] * $totalQuestions))); } // Get stats on profil's user votes according to his friends votes $profileAFS = $profile->getAnswerFriendStats(); if ($profileAFS['votes'] != 0) { Globals::$tpl->assignVar(array('profile_friend_distance' => round(($profileAFS['votes'] - $profileAFS['goodVotes']) / $profileAFS['votes'] * $totalQuestions))); } } // Compute user's feelings $profileFeelings = $profile->getFeelings(); $maxFeelingScore = 0; foreach ($profileFeelings as $total) { $maxFeelingScore = $maxFeelingScore < $total ? $total : $maxFeelingScore; } $feelings = array('Personalité', 'Environement', 'Savoir', 'Experience', 'Réflexion', 'Sensibilité'); $colors = Conf::get('GRAPH_COLORS'); $data = array(); foreach ($feelings as $id => $label) { Globals::$tpl->assignLoopVar('feeling', array('label' => $label, 'percent' => round($maxFeelingScore == 0 ? 0 : $profileFeelings[$id + 1] / $maxFeelingScore * 100))); $data[] = array('value' => ($maxFeelingScore ? 1 - $profileFeelings[$id + 1] / $maxFeelingScore : 0) * 0.95 + 0.05, 'label' => $label, 'color' => $colors[$id]); } Globals::$tpl->assignVar('feeling_data', json_encode($data)); // No friends ? if (count($friends) == 0 && (!isset($pendingFriends) || count($pendingFriends) == 0)) { Globals::$tpl->assignSection('noFriends'); } }
public function actionRename($params) { $view = $this->ajaxView('user'); $view->state = "failed"; if ($params["id"]) { $user = new Model_User($this->getStorage(), $params["id"]); $view->id = $user->getId(); if ($view->id) { $this->canPerform($user, "edit"); $user->username = $_GET["username"]; $user->login = $_GET["login"]; $user->email = $_GET["email"]; $view->username = $user->username; $view->login = $user->login; $view->email = $user->email; if ($errors = $user->validate()) { $view->error = "validation failed"; $view->errors = $errors; } else { $view->state = "renamed"; try { $user->save(); } catch (Exception $e) { $view->state = "failed"; $view->error = $e->getMessage(); } } } } return $view; }
/** * @param Model_User $user * @param $token * @return bool */ public function sendForgotPassToken(Model_User $user, &$token) { $this->setEmailOptions("change_password"); $template = self::SEND_FORGOT_PASS_TOKEN; $this->addTo($user->getEmail()); $token = NL_Crypt::Encrypt(array("id" => $user->getId())); $this->assign("user", $user); $this->assign("token", $token); return $this->sendHtmlTemplate($template, Zend_Mime::ENCODING_8BIT); }