php - Implemeting a User Class that supports multiple login methods -
i've got parent class user has 2 child classes user_instagram , user_email. use these classes support multiple login methods: user can choose login using instagram, email, or both (once using email, , using instagram later).
the user_instagram class contains instagram-specific user parameters (like instagramuserid, bio, etc.). user_email class used typical signups using email/password combo.
i'm trying figure out how implement in way oop-complaint. need able to:
- register user calling
user_instagram->register($token)oruser_email->register($email,$password) - instantiate
userclass in order able access general user information (like$userid) , in order know services he's logged (email, instagram or both).
the way i've implemented bit hard maintain - , i'm pretty sure plain wrong (call gut feeling).
current class structure
the parent class
class user { protected $userid = null; protected $loggedinservices = array('instagram'=>0,'email'=>1); ... } and child classes:
class user_instagram extends user { private $instagram_userid; private $bio; private $profile_pic; private $token; ... public function signin( $token ) { ... } public function register( $token ) { ... } } class user_email extends user { private $email; private $password; # hashed, of course ;) public function signin( $email, $password) { ... } public function register( $email, $password, $passport_number) { ... } } i thought factory class might work here, parent class cannot instantiated in scenario. ideas?
why want inherit user class implement login process. change that:
class user { protected $userid = null; public function setuserid($id) { ... } ... } class login_instagram { private $instagram_userid; private $bio; private $profile_pic; private $token; ... public function __construct(user $user) { ... } public function signin( $token ) { ... $user->setuserid($id); ... } public function register( $token ) { ... } } class login_email { private $email; public function __construct(user $user) { ... } public function signin( $email, $password) { ... $user->setuserid($id); ... } public function register( $email, $password, $passport_number) { ... } } to not implement constructor twice, create parent class , setuserid in parent class. login procedure not need in user class, if process can differ.
any why want store password hash in object? when have validated user, set user id, won't need password hash later.
Comments
Post a Comment