Created
January 15, 2015 10:57
-
-
Save lozadaOmr/b9b67c10e0874f1029b0 to your computer and use it in GitHub Desktop.
Laravel 4.2 User.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Illuminate\Auth\UserTrait; | |
| use Illuminate\Auth\UserInterface; | |
| use Illuminate\Auth\Reminders\RemindableTrait; | |
| use Illuminate\Auth\Reminders\RemindableInterface; | |
| class User extends Eloquent implements UserInterface, RemindableInterface { | |
| use UserTrait, RemindableTrait; | |
| /** | |
| * The database table used by the model. | |
| * | |
| * @var string | |
| */ | |
| protected $table = 'users'; | |
| /** | |
| * Fillable array | |
| * | |
| */ | |
| protected $fillable = array('email', 'password', 'username', 'position', 'mobile'); | |
| /** | |
| * The attributes excluded from the model's JSON form. | |
| * | |
| * @var array | |
| */ | |
| protected $hidden = array('password', 'remember_token'); | |
| /** | |
| * Sets the Validation Rules when Logging In | |
| * | |
| * @var array | |
| */ | |
| public static $loginRules = array( | |
| 'email' => 'required|email', | |
| 'password' => 'required|alpha_dash|min:6' | |
| ); | |
| /** | |
| * Sets the Validation Rules creating a User | |
| * | |
| * @var array | |
| */ | |
| public static $rules = array( | |
| 'email' => 'required|email|unique:users', | |
| 'username' => 'required|min:2|unique:users', | |
| 'position' => 'required|', | |
| 'mobile-number' => 'required|numeric|digits:11', | |
| 'password' => 'required|alpha_dash|min:6|confirmed', | |
| 'password_confirmation' => 'required|alpha_dash|min:6' | |
| ); | |
| /** | |
| * Sets the Validation Rules updating a User | |
| * | |
| * @var array | |
| */ | |
| public static $updateRules = array( | |
| 'username' => 'required|min:2', | |
| 'password' => 'required|alpha_dash|min:6|confirmed', | |
| 'password_confirmation' => 'required|alpha_dash|min:6' | |
| ); | |
| /** | |
| * Defines many-to-many relationship with Module | |
| * | |
| */ | |
| public function permissions() | |
| { | |
| return $this->belongsToMany('Module', 'permissions')->withPivot('add','edit', 'view','delete'); | |
| } | |
| /** | |
| * Get the unique identifier for the user. | |
| * | |
| * @return mixed | |
| */ | |
| public function getAuthIdentifier() | |
| { | |
| return $this->getKey(); | |
| } | |
| /** | |
| * Get the password for the user. | |
| * | |
| * @return string | |
| */ | |
| public function getAuthPassword() | |
| { | |
| return $this->password; | |
| } | |
| /** | |
| * Get the e-mail address where password reminders are sent. | |
| * | |
| * @return string | |
| */ | |
| public function getReminderEmail() | |
| { | |
| return $this->email; | |
| } | |
| /** | |
| * Gets the Remember Token | |
| * | |
| * @return string $this->remember_token | |
| */ | |
| public function getRememberToken() | |
| { | |
| return $this->remember_token; | |
| } | |
| /** | |
| * Set the Remember Token | |
| * | |
| * @param string $value | |
| */ | |
| public function setRememberToken($value) | |
| { | |
| $this->remember_token = $value; | |
| } | |
| /** | |
| * Get the Remember Token name | |
| * | |
| * @return string 'remember_token' | |
| */ | |
| public function getRememberTokenName() | |
| { | |
| return 'remember_token'; | |
| } | |
| /** | |
| * Get the password and Hash it before saving to the database. | |
| * | |
| * @param string $value | |
| */ | |
| public function setPasswordAttribute($value) | |
| { | |
| $this->attributes['password'] = Hash::make($value); | |
| } | |
| /** | |
| * Checks if Guest User input invalid credentials | |
| * | |
| * @param array $credentials | |
| * @return object $validation | |
| */ | |
| public static function loginIsInvalid($credentials) | |
| { | |
| $validation = Validator::make($credentials, self::$loginRules); | |
| if ($validation->fails()) | |
| { | |
| return $validation; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment