Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Essem
Sharkey
Commits
6b6adeaa
Commit
6b6adeaa
authored
7 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
Refactor
parent
86e1ff6a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/models/user.ts
+26
-26
26 additions, 26 deletions
src/models/user.ts
with
26 additions
and
26 deletions
src/models/user.ts
+
26
−
26
View file @
6b6adeaa
...
...
@@ -15,30 +15,6 @@ User.createIndex('account.token');
export
default
User
;
export
function
validateUsername
(
username
:
string
):
boolean
{
return
typeof
username
==
'
string
'
&&
/^
[
a-zA-Z0-9
\-]{3,20}
$/
.
test
(
username
);
}
export
function
validatePassword
(
password
:
string
):
boolean
{
return
typeof
password
==
'
string
'
&&
password
!=
''
;
}
export
function
isValidName
(
name
:
string
):
boolean
{
return
typeof
name
==
'
string
'
&&
name
.
length
<
30
&&
name
.
trim
()
!=
''
;
}
export
function
isValidDescription
(
description
:
string
):
boolean
{
return
typeof
description
==
'
string
'
&&
description
.
length
<
500
&&
description
.
trim
()
!=
''
;
}
export
function
isValidLocation
(
location
:
string
):
boolean
{
return
typeof
location
==
'
string
'
&&
location
.
length
<
50
&&
location
.
trim
()
!=
''
;
}
export
function
isValidBirthday
(
birthday
:
string
):
boolean
{
return
typeof
birthday
==
'
string
'
&&
/^
([
0-9
]{4})\-([
0-9
]{2})
-
([
0-9
]{2})
$/
.
test
(
birthday
);
}
type
IUserBase
=
{
_id
:
mongo
.
ObjectID
;
createdAt
:
Date
;
...
...
@@ -61,8 +37,6 @@ type IUserBase = {
hostLower
:
string
;
};
export
type
IUser
=
ILocalUser
|
IRemoteUser
;
export
interface
ILocalUser
extends
IUserBase
{
host
:
null
;
account
:
{
...
...
@@ -108,12 +82,38 @@ export interface IRemoteUser extends IUserBase {
};
}
export
type
IUser
=
ILocalUser
|
IRemoteUser
;
export
const
isLocalUser
=
(
user
:
any
):
user
is
ILocalUser
=>
user
.
host
===
null
;
export
const
isRemoteUser
=
(
user
:
any
):
user
is
IRemoteUser
=>
!
isLocalUser
(
user
);
export
function
validateUsername
(
username
:
string
):
boolean
{
return
typeof
username
==
'
string
'
&&
/^
[
a-zA-Z0-9
\-]{3,20}
$/
.
test
(
username
);
}
export
function
validatePassword
(
password
:
string
):
boolean
{
return
typeof
password
==
'
string
'
&&
password
!=
''
;
}
export
function
isValidName
(
name
:
string
):
boolean
{
return
typeof
name
==
'
string
'
&&
name
.
length
<
30
&&
name
.
trim
()
!=
''
;
}
export
function
isValidDescription
(
description
:
string
):
boolean
{
return
typeof
description
==
'
string
'
&&
description
.
length
<
500
&&
description
.
trim
()
!=
''
;
}
export
function
isValidLocation
(
location
:
string
):
boolean
{
return
typeof
location
==
'
string
'
&&
location
.
length
<
50
&&
location
.
trim
()
!=
''
;
}
export
function
isValidBirthday
(
birthday
:
string
):
boolean
{
return
typeof
birthday
==
'
string
'
&&
/^
([
0-9
]{4})\-([
0-9
]{2})
-
([
0-9
]{2})
$/
.
test
(
birthday
);
}
export
function
init
(
user
):
IUser
{
user
.
_id
=
new
mongo
.
ObjectID
(
user
.
_id
);
user
.
avatarId
=
new
mongo
.
ObjectID
(
user
.
avatarId
);
...
...
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