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