diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9429109e3..47baa13e2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,7 +17,15 @@ class ApplicationController < Sinatra::Base end post "/signup" do - #your code here + if params[:username] == "" || params[:password] == "" + redirect "/failure" + else + # !usparams[:username] == "") && !(params[:password] == "") + # binding.pry + user = User.new(username: params[:username], password: params[:password]) + user.save + redirect "/login" + end end @@ -32,7 +40,13 @@ class ApplicationController < Sinatra::Base end post "/login" do - ##your code here + user = User.find_by(username: params[:username]) + if user && user.authenticate(params[:password]) + session[:user_id] = user.id + redirect "/account" + else + redirect "/failure" + end end get "/failure" do diff --git a/app/models/user.rb b/app/models/user.rb index 4a57cf079..40f070579 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,3 @@ class User < ActiveRecord::Base + has_secure_password end diff --git a/app/views/login.erb b/app/views/login.erb index a43e6ec70..46b8f7b3f 100644 --- a/app/views/login.erb +++ b/app/views/login.erb @@ -1,3 +1,4 @@ +