diff --git a/Gemfile.lock b/Gemfile.lock index 626ae5e..f83f9d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -132,6 +132,8 @@ GEM net-smtp (0.3.2) net-protocol nio4r (2.5.8) + nokogiri (1.13.8-x86_64-darwin) + racc (~> 1.4) nokogiri (1.13.8-x86_64-linux) racc (~> 1.4) public_suffix (5.0.0) @@ -185,6 +187,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + sqlite3 (1.5.2-x86_64-darwin) sqlite3 (1.5.2-x86_64-linux) stimulus-rails (1.1.0) railties (>= 6.0.0) @@ -214,6 +217,7 @@ GEM zeitwerk (2.6.1) PLATFORMS + x86_64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/app/controllers/domains_controller.rb b/app/controllers/domains_controller.rb index bfc0d77..529b679 100644 --- a/app/controllers/domains_controller.rb +++ b/app/controllers/domains_controller.rb @@ -2,7 +2,11 @@ class DomainsController < ApplicationController helper DnsimpleHelper def index - @domains = Domain.all + if !current_user + redirect_to controller: "users", action: "auth" + else + @domains = Domain.where(users_id: current_user) + end end def dns @@ -15,9 +19,10 @@ def dns def destroy @domain = Domain.find_by(host: params["id"]) if @domain.destroy - redirect_to root_url + redirect_to root_url else - render json: @domain.errors, status: 503 + render json: @domain.errors, status: 418 + end end def email @@ -33,7 +38,7 @@ def settings end def new - @domain = Domain.new(host: params[:host], users_id: session[:current_user_id]) + @domain = Domain.new(host: params[:host], users_id: current_user) if @domain.save redirect_to action: "dns", id: params[:host] else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c353982..63f74d0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,4 +14,15 @@ def logout @_current_user = nil redirect_to root_url end + + def new + @user = User.new(email: params[:email]) + if @user.save + session[:current_user_id] = @user.id + redirect_to root_url + else + render json: @user.errors, status: 503 + end + + end end diff --git a/app/models/user.rb b/app/models/user.rb index 1fa4ccc..c313d5f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,3 @@ class User < ApplicationRecord - validates :user, presence: true validates :email, uniqueness: true end diff --git a/app/views/users/auth.html.erb b/app/views/users/auth.html.erb index 78f4cab..8966f0c 100644 --- a/app/views/users/auth.html.erb +++ b/app/views/users/auth.html.erb @@ -1,2 +1,3 @@ -

Users#auth

-

Find me in app/views/users/auth.html.erb

+

Not built yet

+ +

You've been redirected here because you haven't logged in
To login: `/users/login?id={id}`
To make a new user: `/users/new?email={email}`

diff --git a/config/routes.rb b/config/routes.rb index d49cb25..5d8cef5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,8 +6,11 @@ get '/domains/:id/email', to: "domains#email" get '/domains/:id/links', to: "domains#links" get '/domains/:id/settings', to: "domains#settings" + get '/domains/:id/destroy', to: "domains#destroy" get 'users/auth' get 'users/login' + get 'users/logout' + get 'users/new' # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/")