示例#1
0
文件: memberDao.php 项目: Wooddu/MMNZ
 public function findByUsername($username, $password)
 {
     $row = $this->query("SELECT user_id, username, password, role FROM member WHERE username='******' AND password='******'")->fetch();
     if (!$row) {
         return null;
     }
     $member = new Member();
     MemberMapper::map($member, $row);
     return $member;
 }
示例#2
0
<?php

$errors = array();
$member = null;
// set defaults
$member = new Member();
//Breaking dry principle, but can be fixed
//netbeans wouldnt work until I added the backslash, not 100% if correct
if (array_key_exists('sign_up', $_POST)) {
    $data = array('username' => filter_var($_POST['member']['username'], FILTER_SANITIZE_STRING), 'password' => filter_var($_POST['member']['password'], FILTER_SANITIZE_STRING), 'first_name' => filter_var($_POST['member']['first_name'], FILTER_SANITIZE_STRING), 'last_name' => filter_var($_POST['member']['last_name'], FILTER_SANITIZE_STRING), 'email' => filter_var($_POST['member']['email'], FILTER_SANITIZE_EMAIL));
    // map
    MemberMapper::map($member, $data);
    // validate
    // save
    $dao = new MemberDao();
    $member = $dao->save($member);
    //        put new user in session
    $username = filter_var($_POST['member']['username'], FILTER_SANITIZE_STRING);
    $password = filter_var($_POST['member']['password'], FILTER_SANITIZE_STRING);
    $user = $dao->findByUsername($username, $password);
    $_SESSION['username'] = $user->getUsername();
    $_SESSION['user_id'] = $user->getUser_id();
    Flash::addFlash('You can now share your thoughts on different items and will recieve our monthly heads up. Awesome!');
    // redirect
    Utils::redirect('home');
}