Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Lynchburg Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
Lynchburg
Lynchburg Server
Commits
bce61e2f
Commit
bce61e2f
authored
4 years ago
by
Nils G.
Browse files
Options
Downloads
Patches
Plain Diff
Prvent user with the same user name to enter the same room
parent
1d3ed4d2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
controllers/player.py
+8
-2
8 additions, 2 deletions
controllers/player.py
modules/http_util.py
+2
-1
2 additions, 1 deletion
modules/http_util.py
static/css/base.css
+7
-0
7 additions, 0 deletions
static/css/base.css
views/default/index.html
+21
-1
21 additions, 1 deletion
views/default/index.html
with
38 additions
and
4 deletions
controllers/player.py
+
8
−
2
View file @
bce61e2f
from
parameter_util
import
JSON_BODY
,
JSON_CONTAINS
from
parameter_util
import
JSON_BODY
,
JSON_CONTAINS
from
http_util
import
FAIL
,
CODE_JSON
,
CODE_MISSING
,
CODE_SEMANTIC
,
CODE_GONE
,
CODE_NOTFOUND
from
http_util
import
FAIL
,
CODE_JSON
,
CODE_MISSING
,
CODE_SEMANTIC
,
CODE_GONE
,
CODE_NOTFOUND
,
CODE_CONFLICT
from
room_util
import
ROOM_GET_CODE
from
room_util
import
ROOM_GET_CODE
,
PLAYERS_GET
def
create
():
def
create
():
parameters
=
JSON_BODY
(
request
)
parameters
=
JSON_BODY
(
request
)
...
@@ -22,5 +22,11 @@ def create():
...
@@ -22,5 +22,11 @@ def create():
if
not
room_record
:
if
not
room_record
:
return
(
FAIL
(
CODE_NOTFOUND
))
return
(
FAIL
(
CODE_NOTFOUND
))
players
=
PLAYERS_GET
(
room_record
)
for
player
in
players
:
if
player
[
"
name
"
]
==
user_name
:
return
(
FAIL
(
CODE_CONFLICT
))
db
.
Player
.
insert
(
name
=
user_name
,
room_id
=
room_record
.
id
)
db
.
Player
.
insert
(
name
=
user_name
,
room_id
=
room_record
.
id
)
return
(
200
)
return
(
200
)
This diff is collapsed.
Click to expand it.
modules/http_util.py
+
2
−
1
View file @
bce61e2f
from
gluon
import
*
from
gluon
import
*
CODE_MISSING
=
400
CODE_MISSING
=
400
CODE_NOTFOUND
=
404
CODE_JSON
=
406
CODE_JSON
=
406
CODE_CONFLICT
=
409
CODE_GONE
=
410
CODE_GONE
=
410
CODE_SEMANTIC
=
422
CODE_SEMANTIC
=
422
CODE_NOTFOUND
=
404
def
FAIL
(
_code
):
def
FAIL
(
_code
):
current
.
response
.
status
=
_code
current
.
response
.
status
=
_code
...
...
This diff is collapsed.
Click to expand it.
static/css/base.css
+
7
−
0
View file @
bce61e2f
.error
{
color
:
red
;
}
/* ============== Footer ===================== */
#footer
{
#footer
{
position
:
fixed
;
position
:
fixed
;
...
...
This diff is collapsed.
Click to expand it.
views/default/index.html
+
21
−
1
View file @
bce61e2f
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
<form
id=
"form_login"
>
<form
id=
"form_login"
>
<input
type=
"text"
id=
"room_code"
placeholder=
"Room Code"
maxlength=
"4"
><br><br>
<input
type=
"text"
id=
"room_code"
placeholder=
"Room Code"
maxlength=
"4"
><br><br>
<input
type=
"text"
id=
"user_name"
placeholder=
"User Name"
maxlength=
"15"
><br><br>
<input
type=
"text"
id=
"user_name"
placeholder=
"User Name"
maxlength=
"15"
><br><br>
<span
id=
"form_login_error"
class=
"error"
></span><br>
<input
type=
"submit"
value=
"Enter"
>
<input
type=
"submit"
value=
"Enter"
>
</form>
</form>
</div>
</div>
...
@@ -15,8 +16,27 @@
...
@@ -15,8 +16,27 @@
{{block page_js}}
{{block page_js}}
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
$
(
"
#form_login
"
).
on
(
"
submit
"
,
function
(){
$
(
"
#form_login
"
).
on
(
"
submit
"
,
function
(){
$
(
"
#form_login_error
"
).
html
();
var
payload
=
{
"
room_code
"
:
$
(
"
#room_code
"
).
val
(),
"
user_name
"
:
$
(
"
#user_name
"
).
val
()}
var
payload
=
{
"
room_code
"
:
$
(
"
#room_code
"
).
val
(),
"
user_name
"
:
$
(
"
#user_name
"
).
val
()}
AJAX_JSON
(
"
{{=URL('player', 'create')}}
"
,
payload
,
function
(
code
,
data
){
alert
(
code
);});
AJAX_JSON
(
"
{{=URL('player', 'create')}}
"
,
payload
,
function
(
_code
,
_data
){
switch
(
_code
){
case
200
:
break
;
case
404
:
$
(
"
#form_login_error
"
).
html
(
"
Room could not be found.
"
);
break
;
case
409
:
$
(
"
#form_login_error
"
).
html
(
"
Please choose a different user name.
"
);
break
;
case
422
:
$
(
"
#form_login_error
"
).
html
(
"
Please provide valid values.
"
);
break
;
default
:
$
(
"
#form_login_error
"
).
html
(
"
Error
"
);
}
});
return
false
;
return
false
;
});
});
</script>
</script>
...
...
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