Speaker profile #2

Merged
ignisf merged 5 commits from speaker-profile into master 2014-08-31 16:43:32 +03:00
12 changed files with 143 additions and 36 deletions
Showing only changes of commit 9cca063a1b - Show all commits

View File

@ -2,4 +2,13 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:email, :password, :password_confirmation, :current_password, speaker_profile_attributes: [:first_name, :last_name, :public_email, :organisation, :github, :twitter, :mobile_phone, :biography])
end
end
end

View File

@ -0,0 +1,35 @@
class RegistrationsController < Devise::RegistrationsController
def edit
resource.build_speaker_profile unless resource.speaker_profile.present?
end
def update
@user = User.find(current_user.id)
successfully_updated = if needs_password?(@user, params)
@user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))
else
# remove the virtual current_password attribute
# update_without_password doesn't know how to ignore it
params[:user].delete(:current_password)
@user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
end
if successfully_updated
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
private
def needs_password?(user, params)
user.email != params[:user][:email] ||
params[:user][:password].present? ||
params[:user][:password_confirmation].present?
end
end

View File

@ -0,0 +1,16 @@
class SpeakerProfilesController < ApplicationController
before_filter :authenticate_user!
before_action :assign_speaker_profile
def edit
end
def update
end
private
def assign_speaker_profile
@speaker_profile = SpeakerProfile.find_or_initialize_by(user: current_user)
end
end

View File

@ -7,4 +7,6 @@ class User < ActiveRecord::Base
has_one :speaker_profile
has_many :lectures
has_many :workshops
accepts_nested_attributes_for :speaker_profile, update_only: true
end

View File

@ -1,27 +0,0 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %>
<%= f.input :password_confirmation, required: false %>
<%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>

View File

@ -0,0 +1,30 @@
h2.entry-title Редакция на акаунт
= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f|
= f.error_notification
.form-inputs
h3 Данни за вход в системата
= f.input :email, required: true, autofocus: true
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
p Currently waiting confirmation for: #{resource.unconfirmed_email}
= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false
= f.input :password_confirmation, required: false
= f.input :current_password, hint: "we need your current password to confirm your changes", required: true
.form_inputs
h3 Лекторски профил
= f.simple_fields_for :speaker_profile do |ff|
= ff.input :first_name
= ff.input :last_name
= ff.input :public_email
= ff.input :organisation
= ff.input :github
= ff.input :twitter
= ff.input :mobile_phone, input_html: {value: resource.speaker_profile.mobile_phone.try(:phony_formatted, format: :international)}
= ff.input :biography
.form-actions
= f.button :submit, 'Обнови'

View File

@ -0,0 +1,14 @@
== simple_form_for @speaker_profile do |form|
p
= form.error_notification
.form-inputs
= form.input :first_name, autofocus: true
= form.input :last_name
= form.input :public_email
= form.input :organisation
= form.input :github
= form.input :twitter
= form.input :mobile_phone
= form.input :biography
= form.button :submit

View File

@ -0,0 +1,3 @@
h1.entry-title Редакция на лекторски профил
== render 'form'

View File

@ -38,6 +38,15 @@ bg:
password: Парола
password_confirmation: Отново паролата
remember_me: Запомни ме
speaker_profile:
first_name: Име
last_name: Фамилия
organisation: Организация
public_email: Публичен email
mobile_phone: Мобилен телефон
biography: Биография
github: Github акаунт
twitter: Twitter акаунт
lecture:
title: Заглавие
subtitle: Подзаглавие

View File

@ -12,6 +12,15 @@ bg:
email: Имейл адресът Ви. Ще бъде видим само от организаторите.
password: Парола с дължина между 8 и 128 символа
password_confirmation: Отново въведената отгоре парола
speaker_profile:
first_name: Малкото Ви име
last_name: Фамилното Ви име
organisation: Организацията, която представлявате
public_email: E-mail адрес, който ще бъде видим за посетителите
mobile_phone: Мобилен телефон, който ще бъде видим само за организаторите
biography: Опишете се с няколко изречения в трето лице :).
github: Github акаунтът Ви
twitter: Twitter акаунтът Ви
lecture:
title: Заглавието на лекцията Ви
subtitle: Подзаглавието на лекцията Ви (ако има такова)
@ -30,3 +39,6 @@ bg:
abstract: Резюме на уъркшопа, което да може да бъде прочетено от посетителите
description: Подробно описание на уъркшопа, което да бъде използвано от организаторския екип
notes: Забележки, които искате да споделите с организаторския екип
labels:
user:
a: b

View File

@ -2,7 +2,11 @@ Rails.application.routes.draw do
resources :lectures, only: [:index, :new, :create, :edit, :update, :show]
resources :workshops, only: [:index, :new, :create, :edit, :update, :show]
devise_for :users
devise_for :users, controllers: {registrations: 'registrations'}
resource :user, only: [] do
resource :speaker_profile, only: [:edit, :update]
end
root 'home#index'
# The priority is based upon order of creation: first created -> highest priority.

View File

@ -1,15 +1,15 @@
class CreateSpeakerProfiles < ActiveRecord::Migration
def change
create_table :speaker_profiles do |t|
t.string :first_name, null: false
t.string :last_name, null: false
t.string :first_name
t.string :last_name
t.string :organisation
t.string :public_email
t.string :photo_url, null: false
t.string :mobile_phone, null: false
t.text :biography, null: false
t.string :github, null: false
t.string :twitter, null: false
t.string :photo_url
t.string :mobile_phone
t.text :biography
t.string :github
t.string :twitter
t.timestamps
end