-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobile_number.install
executable file
·127 lines (114 loc) · 3.02 KB
/
mobile_number.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* @file
* Install, update and uninstall functions for the systementity_configfield module.
*/
/**
* Implements hook_field_schema().
*/
function mobile_number_field_schema($field) {
$schema['columns'] = array(
'value' => array(
'type' => 'varchar',
'length' => 19,
'not null' => TRUE,
'default' => '',
),
'country' => array(
'type' => 'varchar',
'length' => 3,
'not null' => TRUE,
'default' => '',
),
'local_number' => array(
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'default' => '',
),
'verified' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'tfa' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
);
$schema['indexes'] = array(
'value' => array('value'),
);
return $schema;
}
/**
* Implements hook_schema().
*/
function mobile_number_schema() {
$schema['mobile_number_verification'] = array(
'description' => 'A table for storing verification codes for mobile numbers.',
'fields' => array(
'token' => array(
'description' => 'Verification token.',
'type' => 'varchar',
'length' => 43,
'not null' => TRUE,
),
'timestamp' => array(
'description' => 'The time when the verification token was created.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'verification_code' => array(
'description' => 'Hash of the code sent to the user.',
'type' => 'varchar',
'length' => 40,
'not null' => TRUE,
),
),
'indexes' => array(
'token_created' => array('timestamp'),
),
'primary key' => array('token'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function mobile_number_install() {
variable_set('mobile_number_secret', drupal_get_token('mobile number secret' . rand(0, 999999999)));
}
/**
* Implements hook_uninstall().
*/
function mobile_number_uninstall() {
variable_del('mobile_number_secret');
variable_del('mobile_number_tfa_field');
}
/**
* Implements hook_requirements().
*/
function mobile_number_requirements($phase) {
$requirements = array();
module_load_include('inc', 'mobile_number', 'include/mobile_number.libphonenumber');
switch ($phase) {
case 'runtime':
$requirements['mobile_number'] = array(
'title' => t('Mobile Number Requirements'),
'description' => t('!libphonenumber library installation.', array(
'!libphonenumber' => l(
t('libphonenumber'), 'https://github.com/giggsey/libphonenumber-for-php',
array('attributes' => array('target' => '_blank'))
),
)),
'severity' => class_exists('\libphonenumber\PhoneNumberUtil') ? REQUIREMENT_OK : REQUIREMENT_ERROR,
'value' => class_exists('\libphonenumber\PhoneNumberUtil') ? t('Installed.') : t('Not installed.'),
);
break;
}
return $requirements;
}