Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
6dc0bb7f
Commit
6dc0bb7f
authored
11 years ago
by
Peter Rotich
Committed by
Jared Hancock
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add UserAccount Model
parent
94eb0480
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.user.php
+169
-3
169 additions, 3 deletions
include/class.user.php
with
169 additions
and
3 deletions
include/class.user.php
+
169
−
3
View file @
6dc0bb7f
...
...
@@ -38,7 +38,7 @@ class UserModel extends VerySimpleModel {
),
'account'
=>
array
(
'list'
=>
false
,
'reverse'
=>
'
Client
Account.user'
,
'reverse'
=>
'
User
Account.user'
,
),
'default_email'
=>
array
(
'null'
=>
true
,
...
...
@@ -73,6 +73,8 @@ class User extends UserModel {
var
$_entries
;
var
$_forms
;
var
$_account
;
function
__construct
(
$ht
)
{
parent
::
__construct
(
$ht
);
// TODO: Make this automatic with select_related()
...
...
@@ -194,9 +196,11 @@ class User extends UserModel {
if
(
!
$this
->
_entries
)
{
$g
=
UserForm
::
getInstance
();
$g
->
setClientId
(
$this
->
id
);
$g
->
save
();
$this
->
_entries
[]
=
$g
;
}
}
return
$this
->
_entries
;
}
...
...
@@ -224,6 +228,67 @@ class User extends UserModel {
return
$this
->
_forms
;
}
function
getAccount
()
{
// XXX: return $this->account;
if
(
!
isset
(
$this
->
_account
))
$this
->
_account
=
UserAccount
::
lookup
(
array
(
'user_id'
=>
$this
->
getId
()));
return
$this
->
_account
;
}
function
getAccountStatus
()
{
if
(
$this
->
getAccount
())
return
(
string
)
$this
->
getAccount
()
->
getStatus
();
return
'Unregistered'
;
}
function
register
(
$vars
,
&
$errors
)
{
// user already registered?
if
(
$this
->
getAccount
())
return
true
;
//Require temp password.
if
(
!
isset
(
$vars
[
'sendemail'
]))
{
if
(
!
$vars
[
'passwd1'
])
$errors
[
'passwd1'
]
=
'Temp. password required'
;
elseif
(
$vars
[
'passwd1'
]
&&
strlen
(
$vars
[
'passwd1'
])
<
6
)
$errors
[
'passwd1'
]
=
'Must be at least 6 characters'
;
elseif
(
$vars
[
'passwd1'
]
&&
strcmp
(
$vars
[
'passwd1'
],
$vars
[
'passwd2'
]))
$errors
[
'passwd2'
]
=
'Password(s) do not match'
;
}
if
(
$errors
)
return
false
;
$account
=
UserAccount
::
create
(
array
(
'user_id'
=>
$this
->
getId
()));
if
(
!
$account
)
return
false
;
$account
->
set
(
'dst'
,
isset
(
$vars
[
'dst'
])
?
1
:
0
);
$account
->
set
(
'timezone_id'
,
$vars
[
'timezone_id'
]);
if
(
$vars
[
'username'
]
&&
strcasecmp
(
$vars
[
'username'
],
$this
->
getEmail
()))
$account
->
set
(
'username'
,
$vars
[
'username'
]);
if
(
!
$vars
[
'sendemail'
])
$account
->
set
(
'passwd'
,
Password
::
hash
(
$vars
[
'passwd1'
]));
//TODO: else $account->sendActivationEmail();
$account
->
save
(
true
);
return
$account
;
}
//TODO: Add organization support
function
getOrg
()
{
return
''
;
}
function
updateInfo
(
$vars
,
&
$errors
)
{
$valid
=
true
;
...
...
@@ -288,13 +353,20 @@ class User extends UserModel {
$this
->
name
=
mb_convert_case
(
$this
->
name
,
MB_CASE_TITLE
);
}
if
(
count
(
$this
->
dirty
))
if
(
count
(
$this
->
dirty
))
//XXX: doesn't work??
$this
->
set
(
'updated'
,
new
SqlFunction
(
'NOW'
));
return
parent
::
save
(
$refetch
);
}
function
delete
()
{
return
parent
::
delete
()
&&
$this
->
default_email
->
delete
();
//TODO: See about deleting other associated models.
// Delete email
if
(
$this
->
default_email
)
$this
->
default_email
->
delete
();
// Delete user
return
parent
::
delete
();
}
}
User
::
_inspect
();
...
...
@@ -482,6 +554,100 @@ class UserEmail extends UserEmailModel {
}
class
UserAccountModel
extends
VerySimpleModel
{
static
$meta
=
array
(
'table'
=>
USER_ACCOUNT_TABLE
,
'pk'
=>
array
(
'id'
),
'joins'
=>
array
(
'user'
=>
array
(
'null'
=>
false
,
'constraint'
=>
array
(
'user_id'
=>
'UserModel.id'
)
),
),
);
}
class
UserAccount
extends
UserAccountModel
{
var
$_options
=
null
;
var
$timezone
;
const
CONFIRMED
=
0x0001
;
const
LOCKED
=
0x0002
;
const
PASSWD_RESET_REQUIRED
=
0x0004
;
private
function
hasStatus
(
$flag
)
{
return
0
!==
(
$this
->
get
(
'status'
)
&
$flag
);
}
private
function
clearStatus
(
$flag
)
{
return
$this
->
set
(
'status'
,
$this
->
get
(
'status'
)
&
~
$flag
);
}
private
function
setStatus
(
$flag
)
{
return
$this
->
set
(
'status'
,
$this
->
get
(
'status'
)
|
$flag
);
}
function
getStatus
()
{
return
$this
->
get
(
'status'
);
}
function
getInfo
()
{
return
$this
->
ht
;
}
function
__toString
()
{
return
(
string
)
$this
->
getStatus
();
}
/*
* This assumes the staff is doing the update
*/
function
update
(
$vars
,
&
$errors
)
{
global
$thisstaff
;
if
(
!
$thisstaff
)
{
$errors
[
'err'
]
=
'Access Denied'
;
return
false
;
}
// TODO: Make sure the username is unique
if
(
!
$vars
[
'timezone_id'
])
$errors
[
'timezone_id'
]
=
'Time zone required'
;
// Changing password?
if
(
$vars
[
'passwd1'
]
||
$vars
[
'passwd2'
])
{
if
(
!
$vars
[
'passwd1'
])
$errors
[
'passwd1'
]
=
'New password required'
;
elseif
(
$vars
[
'passwd1'
]
&&
strlen
(
$vars
[
'passwd1'
])
<
6
)
$errors
[
'passwd1'
]
=
'Must be at least 6 characters'
;
elseif
(
$vars
[
'passwd1'
]
&&
strcmp
(
$vars
[
'passwd1'
],
$vars
[
'passwd2'
]))
$errors
[
'passwd2'
]
=
'Password(s) do not match'
;
}
if
(
$errors
)
return
false
;
$this
->
set
(
'timezone_id'
,
$vars
[
'timezone_id'
]);
$this
->
set
(
'dst'
,
isset
(
$vars
[
'dst'
])
?
1
:
0
);
// Make sure the username is not an email.
if
(
$vars
[
'username'
]
&&
Validator
::
is_email
(
$vars
[
'username'
]))
$vars
[
'username'
]
=
''
;
$this
->
set
(
'username'
,
$vars
[
'username'
]);
if
(
$vars
[
'passwd1'
])
{
$this
->
set
(
'passwd'
,
Passwd
::
hash
(
$vars
[
'passwd'
]));
$this
->
setStatus
(
self
::
CONFIRMED
);
}
return
$this
->
save
(
true
);
}
}
/*
* Generic user list.
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment