XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AbstractUserEditForm.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7require_once XOOPS_ROOT_PATH . '/core/XCube_ActionForm.class.php';
8
9class User_AbstractUserEditForm extends XCube_ActionForm
10{
11 public $mConfig = null;
12
13 public function User_AbstractUserEditForm($userConfig)
14 {
15 self::__construct($userConfig);
16 }
17
18 public function __construct($userConfig)
19 {
20 parent::__construct();
21 $this->mConfig = $userConfig;
22 }
23
24 public function validateUname()
25 {
26 if ($this->get('uname')) {
27 //
28 // uname unique check
29 //
30 $userHandler=&xoops_gethandler('user');
31 $criteria =new CriteriaCompo(new Criteria('uname', $this->get('uname')));
32 if ($this->get('uid') > 0) {
33 $criteria->add(new Criteria('uid', $this->get('uid'), '<>'));
34 }
35 if ($userHandler->getCount($criteria) > 0) {
36 $this->addErrorMessage(_MD_USER_LANG_NICKNAMETAKEN);
37 }
38
39 //
40 // Check allow uname string pattern.
41 //
42 $regex= '';
43 switch ($this->mConfig['uname_test_level']) {
44 case 0:
45 $regex="/[^a-zA-Z0-9\_\-]/";
46 break;
47
48 case 1:
49 $regex="/[^a-zA-Z0-9\_\-<>\,\.\$\%\#\@\!\\\'\"]/";
50 break;
51
52 case 2:
53 $regex="/[\000-\040]/";
54 break;
55 }
56 if (preg_match($regex, $this->get('uname'))) {
57 $this->addErrorMessage(_MD_USER_LANG_INVALIDNICKNAME);
58 }
59
60 //
61 // Check bad uname patterns.
62 //
63 foreach ($this->mConfig['bad_unames'] as $t_uname) {
64 if (!empty($t_uname) && preg_match("/{$t_uname}/i", $this->get('uname'))) {
65 $this->addErrorMessage(_MD_USER_LANG_NAMERESERVED);
66 break;
67 }
68 }
69 }
70 }
71
72 public function validateEmail()
73 {
74 if (strlen($this->get('email')) > 0) {
75 foreach ($this->mConfig['bad_emails'] as $t_email) {
76 if (!empty($t_email) && preg_match("/{$t_email}/i", $this->get('email'))) {
77 $this->addErrorMessage(_MD_USER_ERROR_INVALID_EMAIL);
78 return;
79 }
80 }
81
82 //
83 // email unique check
84 //
85 $userHandler=&xoops_gethandler('user');
86 $criteria =new CriteriaCompo(new Criteria('email', $this->get('email')));
87 if ($this->get('uid') > 0) {
88 $criteria->add(new Criteria('uid', $this->get('uid'), '<>'));
89 }
90 if ($userHandler->getCount($criteria) > 0) {
91 $this->addErrorMessage(_MD_USER_ERROR_EMAILTAKEN);
92 }
93 }
94 }
95
96 public function validateTimezone_offset()
97 {
98 $handler =& xoops_gethandler('timezone');
99 $obj =& $handler->get($this->get('timezone_offset'));
100 if (!is_object($obj)) {
101 $this->addErrorMessage(_MD_USER_ERROR_TIMEZONE);
102 }
103 }
104
105 public function validateUrl()
106 {
107 $t_url = $this->get('url');
108 if (strlen($t_url) > 0) {
109 if (!preg_match('/^https?(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $t_url)) {
110 $this->addErrorMessage(XCube_Utils::formatString(_MD_USER_ERROR_INJURY, _MD_USER_LANG_URL));
111 }
112 }
113 }
114
115 public function validatePass()
116 {
117 // precondition check
118 if (strlen($this->get('pass')) > 0 && !preg_match('/^[\x21-\x7e]+$/', $this->get('pass'))) {
119 $this->addErrorMessage(XCube_Utils::formatString(_MD_USER_ERROR_INJURY, _MD_USER_LANG_PASSWORD));
120 $this->set('pass', null); // reset
121 $this->set('vpass', null);
122 }
123
124 if (strlen($this->get('pass'))>0||strlen($this->get('vpass'))>0) {
125 if ($this->get('pass')!=$this->get('vpass')) {
126 $this->addErrorMessage(_MD_USER_ERROR_PASSWORD);
127 $this->set('pass', null); // reset
128 $this->set('vpass', null);
129 }
130 }
131 }
132}
addErrorMessage( $message)
Adds a message to the form's error message buffer.
static formatString()
[Static] Formats string with special care for international.