use Cake\ORM\Table;
use Cake\Validation\Validator;
+// User auth
+use Cake\Auth\DigestAuthenticate;
+use Cake\Auth\DefaultPasswordHasher;
+
+
/**
* Users Model
*
}
+ /**
+ * @param Event $event
+ * @return bool
+ */
+ public function beforeSave(Event $event)
+ {
+ $entity = $event->data['entity'];
+
+ // Make a password for digest auth.
+ $entity->digest_hash = DigestAuthenticate::password(
+ $entity->username,
+ $entity->password,
+ env('SERVER_NAME')
+ );
+
+ //Make a password for form auth
+ $entity->password = (new DefaultPasswordHasher)->hash($entity->password);
+
+ return true;
+ }
+
+
+ /**
+ * Returns TRUE if the user as know as Administration FALSE otherwise
+ * @param $userId user id Auth
+ * @return bool
+ */
+ public function isAdministration ($userId){
+
+ $administration = $this->UserTypes->find("all")
+ ->select('id')
+ ->where(["cd = " => "Administration"])->first();
+ return $this->exists(["user_type_id"=> $administration->id,"id"=> $userId]);
+ }
+
public function findByType(Query $query, array $options)
{
$query->where([
return $query;
}
+
/**
* Default validation rules.
*