Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
more stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
APLPublic committed Dec 16, 2022
1 parent 4191b1d commit 669ee39
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -214,6 +217,7 @@ GEM
zeitwerk (2.6.1)

PLATFORMS
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
13 changes: 9 additions & 4 deletions app/controllers/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class User < ApplicationRecord
validates :user, presence: true
validates :email, uniqueness: true
end
5 changes: 3 additions & 2 deletions app/views/users/auth.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<h1>Users#auth</h1>
<p>Find me in app/views/users/auth.html.erb</p>
<h1>Not built yet</h1>

<p> You've been redirected here because you haven't logged in<br> To login: `/users/login?id={id}` <br>To make a new user: `/users/new?email={email}`</p>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ("/")
Expand Down

1 comment on commit 669ee39

@reesericci
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was me lol

Please sign in to comment.