Module: Authmotion::EmailLogin

Defined in:
lib/project/authmotion.rb

Instance Method Summary collapse

Instance Method Details

#after_conectionObject



63
# File 'lib/project/authmotion.rb', line 63

def after_conection ; end

#data_create_userObject



100
101
102
# File 'lib/project/authmotion.rb', line 100

def data_create_user
  raise "data_create_user MUST BE IMPLEMENTED"
end

#data_login_userObject

This method is a hash, how we send the data

{login: 'x', password: ''}


96
97
98
# File 'lib/project/authmotion.rb', line 96

def 
  raise "data_login_user MUST BE IMPLEMENTED"
end

#errorsObject



104
105
106
# File 'lib/project/authmotion.rb', line 104

def errors
  raise "errors should be implemented"
end

#errors_model(response) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/project/authmotion.rb', line 42

def errors_model(response)
  message_json = parse(response)
  messages=""
  message_json["errors"].each do |field,message_array|
    messages = " #{messages}\n #{field}: #{message_array.join("\n")}"
  end
  custom_message(messages)
end

#failed_conectionObject

failed conection, should be a lambda



128
129
130
131
132
133
134
135
136
137
# File 'lib/project/authmotion.rb', line 128

def failed_conection
  lambda do |response|
    if response.status_code.to_s =~ /40\d/
      message = "#{@action} failed"
    else
      message = response.error_message
    end
    custom_message(message)
  end 
end

#has_enough_data_login?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/project/authmotion.rb', line 27

def has_enough_data_login?
  if user_field.nil? or password_field.nil?
    raise "You need define email and password field"
  end
  user_valid? and password_field_simple?
end

#has_enough_data_register?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/project/authmotion.rb', line 34

def has_enough_data_register?
  if user_field.nil? or password_field.nil? or password_confirmation_field.nil? 
    raise "You need define email, password and password confirmation field"
  end
  user_valid? and password_register_valid?
end

#login_actionObject

method that should be call it for log in a user



16
17
18
19
20
21
22
23
24
25
# File 'lib/project/authmotion.rb', line 16

def 
  @action = "login"
  waiting_view
  if has_enough_data_login?
    response = conection(,)
  else
    custom_message("All fields are required")
    hide_waiting_view
  end
end

#login_fieldObject



80
81
82
# File 'lib/project/authmotion.rb', line 80

def 
  raise "should be implemented"
end

#other_errorObject



65
66
67
# File 'lib/project/authmotion.rb', line 65

def other_error
  custom_message("Unknow error")
end

#password_confirmation_fieldObject



88
89
90
# File 'lib/project/authmotion.rb', line 88

def password_confirmation_field
  raise "should be implemented"
end

#password_fieldObject



84
85
86
# File 'lib/project/authmotion.rb', line 84

def password_field
  raise "should be implemented"
end

#password_field_simple?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/project/authmotion.rb', line 55

def password_field_simple?
  password_field.text != ""
end

#password_register_valid?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/project/authmotion.rb', line 59

def password_register_valid?
  password_field.text != "" and password_confirmation_field.text == password_field.text
end

#register_actionObject

method that should be call it for register a user



4
5
6
7
8
9
10
11
12
13
# File 'lib/project/authmotion.rb', line 4

def register_action
  @action = "Register"
  waiting_view
  if has_enough_data_register?
    response = conection(url_register,data_register_user)
  else
    custom_message("All fields are required")
    hide_waiting_view
  end
end

#success_conection_loginObject



143
144
145
# File 'lib/project/authmotion.rb', line 143

def 
 lambda{|response| custom_message('Good, user login. May be you need change this :-) ')}
end

#success_conection_registerObject



139
140
141
# File 'lib/project/authmotion.rb', line 139

def success_conection_register
  lambda{|response| custom_message('Good, user register. May be you need change this :-) ')}      
end

#url_log_inObject

Methods for conections



112
113
114
# File 'lib/project/authmotion.rb', line 112

def 
  raise 'should be implemented'
end

#url_registerObject



116
117
118
# File 'lib/project/authmotion.rb', line 116

def url_register
  raise 'should be implemented'
end

#user_fieldObject

This methods should be implemented like a getters. example:

def user_field
  @field #should be UITextField
end


76
77
78
# File 'lib/project/authmotion.rb', line 76

def user_field
  raise "should be implemented"
end

#user_valid?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/project/authmotion.rb', line 51

def user_valid?
  user_field.text != ""
end

#waiting_viewObject



121
122
123
# File 'lib/project/authmotion.rb', line 121

def waiting_view
  raise "waiting_view should be implemented"
end