Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. <form id="frm-signup">
  2. <h5>Email</h5>
  3. <input id="email" type="text" name="email" />
  4. <h5>Password</h5>
  5. <input id="register-password" type="password" name="password" />
  6. /*Pass data*/
  7. <% users = User.new %>
  8. <% users.username = @email %>
  9. <% users.password = @password %>
  10. <% users.save %>
  11. </form>
  12.  
  13. class User < ParseUser
  14. fields :email, :password, :firstName, :lastName
  15. validates_presence_of :email, :password
  16. alias :email :username
  17. validates_length_of :password, :minimum => 8, :allow_blank => false
  18.  
  19. has_many :items, :primary_key => "objectId"
  20. end
  21.  
  22. class UsersController < ApplicationController
  23. def new
  24. @user = User.new
  25. end
  26.  
  27. def create
  28. user = User.authenticate(params[:username], params[:password])
  29.  
  30. @email = params[:email].nil? 1; params[:email]
  31. @username = params[:email].nil? 1; params[:email]
  32. @password = params[:password].nil? 1; params[:password]
  33.  
  34. if user
  35. session[:user_id] = user.id
  36. redirect_to root_url, :notice => "logged in !"
  37. else
  38. flash.now.alert = "Invalid username or password"
  39. render "new"
  40. end
  41. end
  42.  
  43. def index
  44.  
  45. end
  46.  
  47. def destroy
  48. session[:user_id] = nil
  49. redirect_to root_url, :notice => "Logged out!"
  50. end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement