Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace UserAccounts\Model;
- use \PDO;
- require 'DBConnect.php';
- class Account {
- private $id;
- private $firstName;
- private $lastName;
- private $username;
- private $password;
- public function __construct($firstName, $lastName,
- $username, $password, $id=null) {
- $this->id = $id;
- $this->firstName = $firstName;
- $this->lastName = $lastName;
- $this->username = $username;
- $this->password = $password;
- }
- public static function add($account) {
- //Hash password;
- $hashed = password_hash($account->getPassword(),
- PASSWORD_DEFAULT);
- try {
- $db = new DBConnect();
- $conn = $db->getConnection();
- } catch (Exception $ex) {
- throw $ex;
- }
- $insertStat =
- $conn->prepare("INSERT INTO Account(username, password, firstName, lastName) "
- . "VALUES(:username, :password, :firstName, :lastName)");
- $insertStat->bindValue(':username', $account->getUsername());
- $insertStat->bindValue(':password', $hashed);
- $insertStat->bindValue(':firstName', $account->getFirstName());
- $insertStat->bindValue(':lastName', $account->getLastName());
- try {
- $insertStat->execute();
- } catch (Exception $ex) {
- throw $ex;
- }
- return $conn->lastInsertId();
- }
- public function getId() {
- return $this->id;
- }
- public function getFirstName() {
- return $this->firstName;
- }
- public function setFirstName($firstName) {
- $this->firstName = $firstName;
- }
- public function getLastName() {
- return $this->lastName;
- }
- public function setLastName($lastName) {
- $this->lastName = $lastName;
- }
- public function getUsername() {
- return $this->username;
- }
- public function setUsername($username) {
- $this->username = $username;
- }
- public function getPassword() {
- return $this->password;
- }
- public function setPassword($password) {
- $this->password = $password;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement