Skip to content
Snippets Groups Projects
Commit 7ccc6ec3 authored by Gaston Daniel Barreto Sugliani's avatar Gaston Daniel Barreto Sugliani
Browse files

Agregado registro de usuarios para administrador

parent 92ba3f1f
No related branches found
No related tags found
No related merge requests found
// Place all the styles related to the Registrations controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
class RegistrationsController < Devise::RegistrationsController
before_action :authenticate_user!, :redirect_unless_admin, only: [:new, :create]
skip_before_action :require_no_authentication
# GET /resource/sign_up
def new
if admin_signed_in?
super
else
redirect_to root_path
end
end
# POST /resource
def create
if admin_signed_in?
super
else
redirect_to root_path
end
end
private
def admin_signed_in?
current_user.isAdmin?
end
def redirect_unless_admin
unless current_user and admin_signed_in?
flash[:error] = "Exclusivo administradores"
redirect_to root_path
end
end
def sign_up(resource_name, resource)
true
end
end
\ No newline at end of file
module RegistrationsHelper
end
......@@ -7,4 +7,8 @@ class User < ApplicationRecord
validates :username, uniqueness: true
has_many :publications
self.per_page = 12
def isAdmin?
type== "Admin"
end
end
......@@ -7,7 +7,7 @@
</div>
<div class="col-sm-4">
<%= render "users/perfil_lateral" %>
<%= render partial: 'users/perfil_lateral', locals: { user: @user } %>
</div>
</div>
......
<h2>Sign up</h2>
<div class="container">
<h2>Crear Usuario</h2>
<div class="row">
<!-- Lista Ejercicios -->
<div class="col-sm-8">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
......@@ -8,14 +13,14 @@
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>
<div class="field">
<%= f.label :username %><br />
<%= f.email_field :username, autofocus: true, autocomplete: "Nombre de usuario" %>
<%= f.label 'Nombre de usuario' %><br />
<%= f.text_field :username, autofocus: true, autocomplete: "Nombre de usuario" %>
</div>
<div class="field">
<%= f.label :password %>
<%= f.label 'Contraseña' %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<em> Largo mínimo: <%= @minimum_password_length %> caracteres </em>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password" %>
</div>
......@@ -26,8 +31,15 @@
</div>
<div class="actions">
<%= f.submit "Sign up" %>
<%= f.submit "Registrarse" %>
</div>
<% end %>
</div>
<div class="col-sm-4">
<%= render partial: 'users/perfil_lateral', locals: { user: @user } %>
</div>
</div>
</div>
<%= render "devise/shared/links" %>
......@@ -3,7 +3,7 @@
<% end %>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% link_to "Sign up", new_registration_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
......
<% if current_user.isAdmin? %>
<%= link_to "Crear Usuario", new_user_registration_path, {:class=>"list-group-item list-group-item-action"}%>
<% else %>
<%= link_to 'Mis publicaciones', user_path(current_user), {:class=>"list-group-item list-group-item-action"} %>
<% end %>
<%= link_to 'Modificar mi cuenta', edit_user_registration_path , {:class=>"list-group-item list-group-item-action"} %>
<%= link_to "Cerrar Sesión", destroy_user_session_path, {method: :delete, :class=>"list-group-item list-group-item-action"} %>
\ No newline at end of file
......@@ -4,8 +4,8 @@
<i class="bi bi-person-circle" style="font-size: 2rem;"></i>
</div>
<div class="card-body">
Docente: <%= link_to @user.name, "#" %>
<p class="card-text">Institución: <%= @user.institution %></p>
Docente: <%= link_to user.name, "#" %>
<p class="card-text">Institución: <%= user.institution %></p>
<div class="list-group">
<% if user_signed_in? and (params[:id].to_i == current_user.id or request.env['PATH_INFO'] == edit_user_registration_path) %>
<%= render "users/buttons_list" %>
......
......@@ -8,7 +8,7 @@
<!-- Perfil docente -->
<div class="col-sm-4">
<%= render "users/perfil_lateral" %>
<%= render partial: 'users/perfil_lateral', locals: { user: @user } %>
</div>
</div>
......
......@@ -21,7 +21,7 @@ Rails.application.routes.draw do
end
get 'students', to: 'pages#students'
devise_for :users, :path_prefix => 'd'
devise_for :users, :path_prefix => 'd', :controllers => { :registrations => 'registrations'}
resources :users do
resources :publications
......
require 'test_helper'
class RegistrationsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment