Created
December 5, 2019 08:28
-
-
Save DeaVenditama/f11b0d6dce351cff5d2ac90f21df6c21 to your computer and use it in GitHub Desktop.
simpeg part1. models/Pegawai.php
This file contains 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 | |
namespace app\models; | |
use Yii; | |
/** | |
* This is the model class for table "pegawai". | |
* | |
* @property int $id | |
* @property string $nip | |
* @property string $nama | |
* @property string $tempat_lahir | |
* @property string $tanggal_lahir | |
* @property int $agama | |
* @property int $jenis_kelamin | |
* @property int $nikah | |
* @property int $status_pegawai | |
* @property string $alamat | |
* @property string $telepon | |
* @property string $email | |
* @property string $salt | |
* @property string $password | |
* @property string $created_date | |
* @property int $created_by | |
* @property string|null $updated_date | |
* @property int|null $updated_by | |
*/ | |
class Pegawai extends \yii\db\ActiveRecord | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function tableName() | |
{ | |
return 'pegawai'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function rules() | |
{ | |
return [ | |
[['nip', 'nama', 'tempat_lahir', 'tanggal_lahir', 'agama', 'jenis_kelamin', 'nikah', 'status_pegawai', 'alamat', 'telepon', 'email', 'created_date', 'created_by'], 'required'], | |
[['nama', 'alamat', 'salt', 'password'], 'string'], | |
[['tanggal_lahir', 'created_date', 'updated_date'], 'safe'], | |
[['agama', 'jenis_kelamin', 'nikah', 'status_pegawai', 'created_by', 'updated_by'], 'integer'], | |
[['nip', 'tempat_lahir', 'email'], 'string', 'max' => 32], | |
[['telepon'], 'string', 'max' => 15], | |
]; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function attributeLabels() | |
{ | |
return [ | |
'id' => 'ID', | |
'nip' => 'Nip', | |
'nama' => 'Nama', | |
'tempat_lahir' => 'Tempat Lahir', | |
'tanggal_lahir' => 'Tanggal Lahir', | |
'agama' => 'Agama', | |
'jenis_kelamin' => 'Jenis Kelamin', | |
'nikah' => 'Nikah', | |
'status_pegawai' => 'Status Pegawai', | |
'alamat' => 'Alamat', | |
'telepon' => 'Telepon', | |
'email' => 'Email', | |
'salt' => 'Salt', | |
'password' => 'Password', | |
'created_date' => 'Created Date', | |
'created_by' => 'Created By', | |
'updated_date' => 'Updated Date', | |
'updated_by' => 'Updated By', | |
]; | |
} | |
public static function hashPassword($salt,$password) {// Function to create password hash | |
return md5($salt.$password); | |
} | |
public function beforeSave($insert) | |
{ | |
if (!parent::beforeSave($insert)) | |
return false; | |
if($insert) | |
{ | |
$password=$this->password; | |
$salt = $this->generateSalt(); | |
$this->salt = $salt; | |
$this->password = $this->hashPassword($salt,$password); | |
} | |
return true; | |
} | |
protected function generateSalt() | |
{ | |
return uniqid('',true); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment