Created
April 11, 2018 03:13
-
-
Save dphans/33b6cdfeaffbfce453df32bff6d6ba27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dinophan.authapp.models | |
import com.dinophan.authapp.bases.BaseModel | |
class UserModel: BaseModel() { | |
var username: String = String() | |
var password: String = String() | |
override fun validates(): Boolean { | |
return try { | |
this@UserModel.errorMessage = null | |
if (this@UserModel.username.length < 6) { | |
if (this@UserModel.username.isNotEmpty()) { | |
throw Exception("Username must be minimum 6 characters long!") | |
} | |
return false | |
} | |
this@UserModel.errorMessage = null | |
if (this@UserModel.password.length < 6) { | |
if (this@UserModel.password.isNotEmpty()) { | |
throw Exception("Password must be minimum 6 characters long!") | |
} | |
return false | |
} | |
this@UserModel.errorMessage = null | |
true | |
} catch (validationException: Exception) { | |
this@UserModel.errorMessage = validationException.localizedMessage | |
false | |
} | |
} | |
fun validates(confirmationPassword: String?): Boolean { | |
return try { | |
if (confirmationPassword != null && this@UserModel.password != confirmationPassword) { | |
throw Exception("Confirmation password does not match!") | |
} | |
this@UserModel.errorMessage = null | |
this@UserModel.validates() | |
} catch (validationException: Exception) { | |
this@UserModel.errorMessage = validationException.localizedMessage | |
false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment