package ecse321.fall2014.group3.bomberman.database;

/**
 * @author Marco
 */
public class Session {
    private final Database database;
    private final String username;

    private Session(Database database, String username) {
        this.database = database;
        this.username = username;
    }

    public String getUserName() {
        return username;
    }

    public void setPassword(String password) {
        database.setString(username, Database.PASSWORD_KEY, password);
    }

    public void setRealName(String realName) {
        database.setString(username, Database.REALNAME_KEY, realName);
    }

    public String getPassword() {
        return database.getString(username, Database.PASSWORD_KEY);
    }

    public int getLevel() {
        return database.getInt(username, Database.LEVEL_KEY);
    }

    public int getScore() {
        return database.getInt(username, Database.SCORE_KEY);
    }

    public static Session open(Database database, String username, String password) {
        if (database.getString(username, Database.USERNAME_KEY) == null) {
            return null;
        }
        final String pass = database.getString(username, Database.PASSWORD_KEY);
        if (!password.equals(pass)) {
            return null;
        }
        return new Session(database, username);
    }

    public static Session create(Database database, String username, String password, String realname) {
        if (database.getString(username, Database.USERNAME_KEY) != null) {
            return null;
        }
        database.setString(username, Database.USERNAME_KEY, username);
        database.setString(username, Database.PASSWORD_KEY, password);
        database.setString(username, Database.REALNAME_KEY, realname);
        database.setInt(username, Database.SCORE_KEY, 0);
        database.setInt(username, Database.LEVEL_KEY, 1);
        return new Session(database, username);
    }
}

@@ -358,32 +358,141 @@
 sername;%0A    %7D%0A%0A
+    public String getPassword() %7B%0A        return database.getString(username, Database.PASSWORD_KEY);%0A    %7D%0A%0A
     public void 
@@ -736,34 +736,28 @@
  public 
-Str
 in
-g
+t
  get
-Password
+Level
 () %7B%0A   
@@ -772,38 +772,35 @@
 urn database.get
-String
+Int
 (username, Datab
@@ -799,32 +799,29 @@
 e, Database.
-PASSWORD
+LEVEL
 _KEY);%0A    %7D
@@ -829,37 +829,38 @@
 %0A    public 
-int g
+void s
 etLevel(
 ) %7B%0A        
@@ -839,32 +839,41 @@
 c void setLevel(
+int level
 ) %7B%0A        retu
@@ -860,39 +860,32 @@
 evel) %7B%0A        
-return 
 database.getInt(
@@ -869,33 +869,33 @@
        database.
-g
+s
 etInt(username, 
@@ -904,32 +904,39 @@
 tabase.LEVEL_KEY
+, level
 );%0A    %7D%0A%0A    pu

Add setLevel to Session