Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <?php
  2.  
  3. namespace UserAccounts\Model;
  4.  
  5. use \PDO;
  6.  
  7. require 'DBConnect.php';
  8. class Account {
  9. private $id;
  10. private $firstName;
  11. private $lastName;
  12. private $username;
  13. private $password;
  14.  
  15. public function __construct($firstName, $lastName,
  16. $username, $password, $id=null) {
  17. $this->id = $id;
  18. $this->firstName = $firstName;
  19. $this->lastName = $lastName;
  20. $this->username = $username;
  21. $this->password = $password;
  22. }
  23.  
  24. public static function add($account) {
  25. //Hash password;
  26. $hashed = password_hash($account->getPassword(),
  27. PASSWORD_DEFAULT);
  28.  
  29. try {
  30. $db = new DBConnect();
  31. $conn = $db->getConnection();
  32. } catch (Exception $ex) {
  33. throw $ex;
  34. }
  35.  
  36. $insertStat =
  37. $conn->prepare("INSERT INTO Account(username, password, firstName, lastName) "
  38. . "VALUES(:username, :password, :firstName, :lastName)");
  39. $insertStat->bindValue(':username', $account->getUsername());
  40. $insertStat->bindValue(':password', $hashed);
  41. $insertStat->bindValue(':firstName', $account->getFirstName());
  42. $insertStat->bindValue(':lastName', $account->getLastName());
  43.  
  44. try {
  45. $insertStat->execute();
  46. } catch (Exception $ex) {
  47. throw $ex;
  48. }
  49.  
  50. return $conn->lastInsertId();
  51. }
  52.  
  53. public function getId() {
  54. return $this->id;
  55. }
  56.  
  57. public function getFirstName() {
  58. return $this->firstName;
  59. }
  60.  
  61. public function setFirstName($firstName) {
  62. $this->firstName = $firstName;
  63. }
  64.  
  65. public function getLastName() {
  66. return $this->lastName;
  67. }
  68.  
  69. public function setLastName($lastName) {
  70. $this->lastName = $lastName;
  71. }
  72.  
  73. public function getUsername() {
  74. return $this->username;
  75. }
  76.  
  77. public function setUsername($username) {
  78. $this->username = $username;
  79. }
  80.  
  81. public function getPassword() {
  82. return $this->password;
  83. }
  84.  
  85. public function setPassword($password) {
  86. $this->password = $password;
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement