laravel-nami-api/src/NamiUser.php

80 lines
1.9 KiB
PHP
Raw Normal View History

2020-06-27 23:45:49 +02:00
<?php
namespace Zoomyboy\LaravelNami;
2021-11-17 22:33:25 +01:00
use Cache;
2020-06-27 23:45:49 +02:00
use Illuminate\Contracts\Auth\Authenticatable;
2021-06-19 00:44:56 +02:00
use Illuminate\Database\Eloquent\Model;
2020-06-27 23:45:49 +02:00
2021-06-21 22:37:23 +02:00
class NamiUser implements Authenticatable {
2020-06-27 23:45:49 +02:00
2021-06-18 19:29:21 +02:00
public $mglnr;
2021-06-18 23:26:21 +02:00
public $password;
2021-11-17 22:33:25 +01:00
public string $firstname;
public string $lastname;
public int $group_id;
2020-06-27 23:45:49 +02:00
2021-06-21 22:37:23 +02:00
public function __construct($attributes) {
$this->mglnr = $attributes['mglnr'];
$this->password = $attributes['password'];
2021-11-17 22:33:25 +01:00
$this->firstname = $attributes['firstname'];
$this->lastname = $attributes['lastname'];
$this->group_id = $attributes['group_id'];
2021-06-21 22:37:23 +02:00
}
public static function fromPayload($payload) {
$user = new static([
'mglnr' => data_get($payload, 'credentials.mglnr'),
'password' => data_get($payload, 'credentials.password'),
2021-11-17 22:33:25 +01:00
'firstname' => data_get($payload, 'firstname'),
'lastname' => data_get($payload, 'lastname'),
'group_id' => data_get($payload, 'group_id'),
2021-06-21 22:37:23 +02:00
]);
return $user;
2020-06-27 23:45:49 +02:00
}
2021-06-19 00:44:56 +02:00
public function api() {
return Nami::login($this->mglnr, $this->password);
2020-06-27 23:45:49 +02:00
}
public function getNamiGroupId() {
2021-11-17 22:33:25 +01:00
return $this->group_id;
2020-06-27 23:45:49 +02:00
}
public function getAuthIdentifierName() {
return 'mglnr';
}
2021-06-21 22:37:23 +02:00
public function getMglnr() {
return $this->mglnr;
2021-06-19 00:44:56 +02:00
}
2021-06-21 22:37:23 +02:00
public function getFirstname() {
2021-11-17 22:33:25 +01:00
return $this->firstname;
2021-06-21 22:37:23 +02:00
}
public function getLastname() {
2021-11-17 22:34:24 +01:00
return $this->lastname;
2021-06-19 00:44:56 +02:00
}
2020-06-27 23:45:49 +02:00
public function getAuthIdentifier() {
return $this->{$this->getAuthIdentifierName()}.'-'.$this->groupid;
}
public function getAuthPassword() {
return null;
}
public function getRememberToken() {
return null;
}
public function setRememberToken($value) {}
public function getRememberTokenName() {
return null;
}
2021-06-21 22:37:23 +02:00
2020-06-27 23:45:49 +02:00
}