Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MilderJoghurt
rlf-server
Commits
e7148c15
Commit
e7148c15
authored
Jun 16, 2015
by
Fjen Undso
Browse files
models/Session: generate a 6 digit session id
parent
3108fd87
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/models/QuestionAnswer.java
View file @
e7148c15
...
...
@@ -16,6 +16,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public
class
QuestionAnswer
extends
Model
{
private
static
final
long
serialVersionUID
=
524971764571966919L
;
@Id
public
Long
id
;
...
...
app/models/Session.java
View file @
e7148c15
...
...
@@ -3,6 +3,7 @@ package models;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Random
;
import
javax.persistence.CascadeType
;
import
javax.persistence.Column
;
...
...
@@ -10,8 +11,6 @@ import javax.persistence.Entity;
import
javax.persistence.Id
;
import
javax.persistence.OneToMany
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
play.data.format.Formats
;
import
play.data.validation.Constraints
;
import
play.db.ebean.Model
;
...
...
@@ -21,9 +20,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public
class
Session
extends
Model
{
private
static
final
long
serialVersionUID
=
-
6908035273109180056L
;
@Id
@Constraints
.
MinLength
(
5
)
public
String
id
;
@Constraints
.
MinLength
(
6
)
public
Integer
id
;
private
final
int
IDMIN
=
100000
;
private
final
int
IDMAX
=
1000000
;
@Constraints
.
Required
public
String
owner
;
...
...
@@ -57,11 +61,18 @@ public class Session extends Model {
}
public
Session
(
String
owner
,
String
name
)
{
// crappy easy readable random id
Random
rnd
=
new
Random
();
Integer
id
;
do
{
// try to find a unique id. not threadsafe...
id
=
rnd
.
nextInt
(
IDMAX
-
IDMIN
)
+
IDMIN
;
}
while
(
Session
.
find
.
byId
(
id
.
toString
())
!=
null
);
this
.
id
=
id
;
this
.
owner
=
owner
;
this
.
name
=
name
;
this
.
open
=
true
;
// crappy easy readable random id
this
.
id
=
RandomStringUtils
.
randomAlphanumeric
(
5
).
toUpperCase
();
}
public
Session
(
String
owner
,
String
name
,
Boolean
open
,
Date
date
)
{
...
...
app/models/Vote.java
View file @
e7148c15
...
...
@@ -17,6 +17,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public
class
Vote
extends
Model
{
private
static
final
long
serialVersionUID
=
-
8899299894433057522L
;
@Id
public
Long
id
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment