Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userpasswordtable.php
1<?php
10
11use Bitrix\Main;
15
33{
34 use Data\Internal\DeleteByFilterTrait;
35
36 public static function getTableName()
37 {
38 return 'b_user_password';
39 }
40
41 public static function getMap()
42 {
43 return [
44 (new Fields\IntegerField("ID"))
45 ->configurePrimary(true)
46 ->configureAutocomplete(true),
47
48 (new Fields\IntegerField("USER_ID"))
49 ->addValidator(new Fields\Validators\ForeignValidator(Main\UserTable::getEntity()->getField('ID'))),
50
51 (new Fields\StringField("PASSWORD")),
52
53 (new Fields\DatetimeField("DATE_CHANGE")),
54
55 (new Fields\Relations\Reference(
56 'USER',
57 Main\UserTable::class,
58 Join::on('this.USER_ID', 'ref.ID')
59 ))->configureJoinType('inner'),
60 ];
61 }
62
63 public static function passwordExpired($userId, $days)
64 {
65 $date = new Main\Type\DateTime();
66 $date->add("-{$days}D");
67
68 $prevPassword = static::query()
69 ->where("USER_ID", $userId)
70 ->where("DATE_CHANGE", ">", $date)
71 ->setLimit(1)
72 ->fetch();
73
74 return !$prevPassword;
75 }
76
77 public static function getUserPasswords($userId, $limit)
78 {
79 return static::query()
80 ->addSelect("PASSWORD")
81 ->where("USER_ID", $userId)
82 ->addOrder("ID", "DESC")
83 ->setLimit($limit)
84 ->fetchAll();
85 }
86}