Skip to content
Open

Done #1248

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
require "./config/environment"
require "sinatra/activerecord/rake"
require_relative "./config/environment"
require "sinatra/activerecord/rake"

task :console do
Pry.start
end
33 changes: 25 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,42 @@ class ApplicationController < Sinatra::Base

post "/signup" do
#your code here

end

get '/account' do
@user = User.find(session[:user_id])
erb :account
@user = User.new(:username => params[:username], :password => params[:password])

if @user.save
redirect "/login"
else
redirect "/failure"
end
end


get "/login" do
erb :login
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 "/account" do
# @user = User.find(session[:user_id])
if logged_in?
erb :account
else
redirect "/login"
end
end

get "/failure" do
erb :failure
erb :failure
end

get "/logout" do
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class User < ActiveRecord::Base
has_secure_password
end
14 changes: 13 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
require './app/controllers/application_controller'

run ApplicationController

run ApplicationController



# require_relative './config/environment'

# if ActiveRecord::Migrator.need_migration?
# raise 'Migrations are pending. Run 'rake db:migrate' to resolve the issue.'
# end

# use Rack::MethodOverride
# run ApplicationController
15 changes: 14 additions & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
require 'bundler'
Bundler.require


configure :development do
set :database, {adapter: "sqlite3", database: "db/database.sqlite3"}
end
require_relative '../app/controllers/application_controller.rb'
require_all 'app/models'
require_all 'app/models'



# require 'bundler'
# Bundler.require

# ActiveRecord::Base.establish_connection(
# :adapter => "sqlite3",
# :database => "db/database.sqlite3"
# )

# require_all 'app'
Empty file added db/development.sqlite
Empty file.
8 changes: 8 additions & 0 deletions db/migrate/20210619044238_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :username
t.string :password_digest
end
end
end
20 changes: 20 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20210619044238) do

create_table "users", force: :cascade do |t|
t.string "username"
t.string "password_digest"
end

end