Created
September 3, 2014 20:20
-
-
Save PirosB3/1627bdd6cd9581ba958f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from terminal: | |
rails new penceme | |
brew install imagemagick | |
1) User model | |
- username | |
- password | |
1) validates the presence | |
2) validates the format of the email field | |
3) validates that the password has length > 5 | |
4) validates that the username is unique | |
5) validates that the username is unique | |
validates :field_name, :validation_type => validation attributes | |
validates :username, :presence => true | |
:presence, | |
:uniqueness, | |
:length => {:minimum => number } | |
:format => a regular expression | |
/[h-b]ello/ => [hello, bello] | |
[email protected] | |
[email protected] | |
def is_valid_email(email) | |
# return true if email is correct | |
# return false if email is not correct | |
if it has en ampersand | |
if it has a dot after the ampersand | |
its a valid email | |
else | |
it is not a valid email | |
end | |
is_valid_email("pir!/"T!/£"[email protected]") => true | |
is_valid_email("fuck you") => false | |
/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i | |
rails has many controllers | |
a controller has many actions | |
connect the url "/login" with the new action inside the sessions controller | |
->>>>>>> HERE | |
models: the DATA!!! in this case: the User model /app/models/user | |
controllers: are parts of CODE that connect ROUTES to ACTIONS | |
ROUTES are "/login", "/products/new" these are all URLS | |
views: are the HTML | |
when I go to /login | |
in ROUTES | |
"login" is matched to "sessions" controller, "new" action | |
IN CONTROLLERS | |
"new" action renders the "new" view (new.html.erb) | |
IN VIEWS | |
"new" is shown the web page | |
FORMS | |
forms have 1 or more FIELDS | |
each FIELD has an input | |
each FIELD has an IDENTIFIER (ID) | |
Each form has a SUBMIT button | |
FORMS has a URL to post information to | |
<%= form_tag "/login" do %> | |
<%= label_tag :email %></br> | |
<%= text_field_tag :email %> </br> | |
<%= label_tag :password %></br> | |
<%= password_field_tag :password %></br> | |
<%= submit_tag "Login" %></br> | |
<% end %> | |
render :text => params.to_s | |
def authenticate | |
# Get the email address from the login form | |
email = params[:email] | |
# Get the password from the login form | |
password = params[:password] | |
# Get the user from the DATABASE, using the User model defined in user.rb | |
user = User.find_by_email(email) | |
# if the user does not exist, render an invalid text | |
if user is null | |
render :text => "No user with this email..." | |
end | |
# Check that the password of the user model is the same as the password in the parameters (defined on L121) | |
if user.password == password | |
render :text => "Woohoo!" | |
else | |
render :text => "Invalid information" | |
end | |
end | |
---------------------------------- | |
---------------------------------- | |
# HOMEWORKS | |
PART 1) modify the sessions#authenticate | |
if AUTH is valid: | |
render the "valid" view | |
if AUTH is invalid | |
render the "invalid" view | |
PART 2) create a new routes, a new controller and a new view | |
create a new URL called /hello, that connects to "hello#world" ("Hello" controller, "World" action), | |
that renders the :world view | |
PART 3) familiarize with authentication, the stuff that I did for you | |
FAMILIARIZE and USE https://github.com/PirosB3/eduardo_proj | |
- create a new user through the terminal | |
- login throught /login URL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment