Skip to content

How To Modify For Your Own Use

İhsan Işık edited this page Apr 27, 2017 · 6 revisions

Introduction

If you're interested in modifying this app and in some way incorporating it into your own system, you're absolutely welcome to. Here you will find some extra info and a few things to watch out for during the process.

How does Tensuu make all its users share a single realm?

It's the easy trick we use. We don't actually use realm's authentication features for our users, instead we use a single "owner" account to sign into a single realm. We then have a User model (table) for normal app users and the login screen simply checks whether a user with the given credentials exist in our realm (database). The Admin Tools in the app itself allow adding more users or modifying existing

What do I need to do?

1. Deploy a server & create a user

As far as Realm Object Server goes, there's nothing special going on for Tensuu. Just deploy a server in its default state, and you should be good to go. Once your server is up and running, create a user account to use for your client app.

2. Configure ROS in the client

Create a copy of the Realm configuration sample class and change the credentials info to whatever you made in step 1.

3. Create the first user

Add some temporary code like the following after the MainPresenters SyncUser.currentUser() != null check:

val user = User()
user.email = "someone@somewhere.com"
user.password = "something"
user.isAdmin = true
user.canModify = true
realm.executeTransaction {
    it.copyToRealmOrUpdate(user)
}

Don't forget to remove it once the user is created.

4. Import your students

You can user the above method to import your Students too:

realm.executeTransaction {
    it.createOrUpdateAllFromJson(Student::class.java, assets.open("students.json"))
}

You will need to put your JSON dataset under assets/students.json. Example:

[
  {
    "id": 1,
    "ssid": "BS000001",
    "firstName": "Eliseo",
    "lastName": "Swaney",
    "grade": "1A",
    "floor": 1
  },
  {
    "id": 2,
    "ssid": "BS000002",
    "firstName": "Eddie",
    "lastName": "Čosić",
    "grade": "1B",
    "floor": 1
  }
]

Note on security

Being written rather quickly for internal use, security honestly didn't receive much attention. Passwords are stored in plain text and Realm isn't encrypted. All users can change anything in the db (e.g. their own or another user's isAdmin flag) technically. It's just that the UI code applies restrictions.