Guest User

Untitled

a guest
Apr 18th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package com.dinophan.authapp.models
  2.  
  3. import com.dinophan.authapp.bases.BaseModel
  4.  
  5. class UserModel: BaseModel() {
  6.  
  7. var username: String = String()
  8. var password: String = String()
  9.  
  10. override fun validates(): Boolean {
  11. return try {
  12. this@UserModel.errorMessage = null
  13.  
  14. if (this@UserModel.username.length < 6) {
  15. if (this@UserModel.username.isNotEmpty()) {
  16. throw Exception("Username must be minimum 6 characters long!")
  17. }
  18. return false
  19. }
  20. this@UserModel.errorMessage = null
  21.  
  22. if (this@UserModel.password.length < 6) {
  23. if (this@UserModel.password.isNotEmpty()) {
  24. throw Exception("Password must be minimum 6 characters long!")
  25. }
  26. return false
  27. }
  28. this@UserModel.errorMessage = null
  29.  
  30. true
  31. } catch (validationException: Exception) {
  32. this@UserModel.errorMessage = validationException.localizedMessage
  33. false
  34. }
  35. }
  36.  
  37. fun validates(confirmationPassword: String?): Boolean {
  38. return try {
  39. if (confirmationPassword != null && this@UserModel.password != confirmationPassword) {
  40. throw Exception("Confirmation password does not match!")
  41. }
  42. this@UserModel.errorMessage = null
  43.  
  44. this@UserModel.validates()
  45. } catch (validationException: Exception) {
  46. this@UserModel.errorMessage = validationException.localizedMessage
  47. false
  48. }
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment