/** * This method controls what happens when you move to /overview/showProfile in your app. * Shows the (public) details of the selected user. * @param $user_id int id the the user */ public function showProfile($user_id) { if (isset($user_id)) { $this->View->render('profile/showProfile', array('user' => UserModel::getPublicProfileOfUser($user_id))); } else { Redirect::home(); } }
/** * Writes the new account type marker to the database and to the session * * @param $type * * @return bool */ public static function saveRoleToDatabase($type) { // if $type is not 1 or 2 if (!in_array($type, [1, 2])) { return false; } $user = UserModel::getPublicProfileOfUser(Session::get('user_id')); $user->setUserAccountType($type); $user->save(); if ($user) { Session::set('user_account_type', $type); return true; } return false; }
/** * Write remember-me token into database and into cookie * Maybe splitting this into database and cookie part ? * * @param $user_id */ public static function setRememberMeInDatabaseAndCookie($user_id) { // generate 64 char random string $random_token_string = hash('sha256', mt_rand()); // write that token into database $user = UserModel::getPublicProfileOfUser($user_id); $user->setUserRememberMeToken($random_token_string); $user->save(); // generate cookie string that consists of user id, random string and combined hash of both $cookie_string_first_part = $user_id . ':' . $random_token_string; $cookie_string_hash = hash('sha256', $cookie_string_first_part); $cookie_string = $cookie_string_first_part . ':' . $cookie_string_hash; // set cookie setcookie('remember_me', $cookie_string, time() + Config::get('COOKIE_RUNTIME'), Config::get('COOKIE_PATH')); }
</tr> </thead> <tbody> <?php foreach ($res as $note) { ?> <tr> <td><?php echo $note->note_id; ?> </td> <td><a href="<?php echo Config::get('URL') . "profile/showProfile/" . $note->user_id; ?> "><?php echo UserModel::getPublicProfileOfUser($note->user_id)->user_name; ?> </a></td> <td><?php echo htmlentities($note->note_text); ?> </td> <td><a href="<?php echo Config::get('URL') . 'note/delete/' . $note->note_id; ?> ">Delete</a></td> </tr> <?php } ?> </tbody>
<tr> <td><?php echo $class->class_id; ?> </td> <td><?php echo $class->class_name; ?> </td> <td><?php echo $class->num_paragraphs; ?> </td> <td><?php echo $class->class_key; ?> </td> <td><?php echo UserModel::getPublicProfileOfUser($class->instructor_id)->user_name; ?> </td> </tr> <?php } ?> </table> <input type="submit"> </form> </div> </div>