Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
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
WIMMA Lab 2019
Overflow
ehasa-backend
Commits
27de3ebd
Commit
27de3ebd
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
login exceptions
parent
32f2cf56
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#63977
passed
5 years ago
Stage: purge
Stage: e2e-test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/user/user.service.ts
+44
-46
44 additions, 46 deletions
src/user/user.service.ts
with
44 additions
and
46 deletions
src/user/user.service.ts
+
44
−
46
View file @
27de3ebd
import
{
Injectable
,
HttpException
,
HttpStatus
}
from
'
@nestjs/common
'
;
import
{
Repository
}
from
"
typeorm
"
;
import
{
InjectRepository
}
from
"
@nestjs/typeorm
"
;
import
{
Repository
}
from
'
typeorm
'
;
import
{
InjectRepository
}
from
'
@nestjs/typeorm
'
;
import
{
PersonEntity
}
from
'
./user.entity
'
;
import
{
UserDTO
}
from
'
./user.dto
'
;
...
...
@@ -9,56 +9,54 @@ import { GameDTO } from '../game/game.dto';
@
Injectable
()
export
class
UserService
{
constructor
(
@
InjectRepository
(
PersonEntity
)
private
userRepository
:
Repository
<
PersonEntity
>
,
@
InjectRepository
(
GameEntity
)
private
gameRepository
:
Repository
<
GameEntity
>
)
{
}
constructor
(
@
InjectRepository
(
PersonEntity
)
private
userRepository
:
Repository
<
PersonEntity
>
,
@
InjectRepository
(
GameEntity
)
private
gameRepository
:
Repository
<
GameEntity
>
,
)
{}
async
register
(
data
:
UserDTO
)
{
const
{
name
}
=
data
;
let
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}
});
if
(
user
)
{
throw
new
HttpException
(
'
User already exists
'
,
HttpStatus
.
BAD_REQUEST
);
}
user
=
await
this
.
userRepository
.
create
(
data
);
await
this
.
userRepository
.
save
(
user
);
return
user
.
tokenObject
();
async
register
(
data
:
UserDTO
)
{
const
{
name
}
=
data
;
let
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}
});
if
(
user
)
{
throw
new
HttpException
(
'
User already exists
'
,
HttpStatus
.
BAD_REQUEST
);
}
user
=
await
this
.
userRepository
.
create
(
data
);
await
this
.
userRepository
.
save
(
user
);
return
user
.
tokenObject
();
}
async
login
(
data
:
UserDTO
)
{
try
{
const
{
name
,
password
}
=
data
;
const
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}
});
if
(
!
user
||
!
(
await
user
.
comparePassword
(
password
)))
{
throw
new
HttpException
(
'
invalid password
'
,
HttpStatus
.
BAD_REQUEST
);
}
return
user
.
tokenObject
();
}
catch
(
error
)
{
throw
new
HttpException
(
error
.
message
,
HttpStatus
.
BAD_REQUEST
);
}
async
login
(
data
:
UserDTO
)
{
const
{
name
,
password
}
=
data
;
const
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}
});
if
(
!
user
)
{
throw
new
HttpException
(
'
User does not exist
'
,
HttpStatus
.
BAD_REQUEST
);
}
// liitytään peliin
async
joinGame
(
game
:
GameDTO
,
data
:
UserDTO
)
{
try
{
// etsi peli valinnan mukaan ja otetaan käyttäjän rooli kyseisestä pelistä talteen
const
role
=
await
this
.
gameRepository
.
findOne
();
return
role
;
}
catch
(
error
)
{
return
error
.
message
;
}
if
(
!
(
await
user
.
comparePassword
(
password
)))
{
throw
new
HttpException
(
'
Invalid password
'
,
HttpStatus
.
BAD_REQUEST
);
}
return
user
.
tokenObject
();
}
// liitytään
factionii
async
join
Faction
(
game
:
GameDTO
,
data
:
UserDTO
)
:
Promise
<
boolean
>
{
try
{
// tarkistetaan factionin salasana
return
true
;
}
catch
(
error
)
{
return
error
;
}
// liitytään
peliin
async
join
Game
(
game
:
GameDTO
,
data
:
UserDTO
)
{
try
{
// etsi peli valinnan mukaan ja otetaan käyttäjän rooli kyseisestä pelistä talteen
const
role
=
await
this
.
gameRepository
.
findOne
()
;
return
role
;
}
catch
(
error
)
{
return
error
.
message
;
}
}
// liitytään factionii
async
joinFaction
(
game
:
GameDTO
,
data
:
UserDTO
):
Promise
<
boolean
>
{
try
{
// tarkistetaan factionin salasana
return
true
;
}
catch
(
error
)
{
return
error
;
}
}
}
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