Commit 9ea7fa6a by Thanh Hung Pham

Upload fil

parent 7bc102de
class ConfirmationsController < Devise::ConfirmationsController
def update_confirm
@user = User.find_by(params[:user][:id])
@user.save_file(params[:user][:cv_name])
@user.skip_password_validation = false
@user.skip_fullname_validation = false
if @user.update_attributes(user_params)
......
class User < ApplicationRecord
attr_accessor :skip_password_validation, :skip_fullname_validation
attr_accessor :skip_password_validation, :skip_fullname_validation, :upload
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
......@@ -9,4 +9,21 @@ class User < ApplicationRecord
validates :email, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }
validates_presence_of :fullname, message: "can't be empty", unless: :skip_fullname_validation
validates_presence_of :password, message: "can't be empty", unless: :skip_fullname_validation
def save_file(upload)
file_name = upload.original_filename if upload != ''
file = upload.read
file_type = file_name.split('.').last
new_name_file = Time.now.to_i
name_folder = 'upload'
new_file_name_with_type = "#{new_name_file}." + file_type
image_root = "#{RAILS.root}"
Dir.mkdir(image_root + "#{name_folder}")
File.open(image_root + "#{name_folder}/" + new_file_name_with_type, 'wb') do |f|
f.write(file)
end
end
end
......@@ -2,7 +2,7 @@
<div class="well">
<h2>Register</h2>
<%= form_for(resource, url: confirmations_update_confirm_path(resource), html: { method: :post }) do |f| %>
<%= form_for(resource, url: confirmations_update_confirm_path(resource), html: { method: :post }, multipart: true) do |f| %>
<%= devise_error_messages! %>
<div class="form-group">
......
<%- provide(:title, 'Register') -%>
<%- provide(:title, 'My Page') -%>
<div class="well">
<h2>Register</h2>
<h2>My Page</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
......@@ -14,23 +14,26 @@
</div>
<div class="form-group">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
<span class="help-block">leave blank if you don't want to change it</span>
<%= f.label :fullname %>
<%= f.text_field :fullname, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
<%= f.label :cv_name %>
<%= f.file_field :cv_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password, 'New password' %><br />
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :current_password %>
<%= f.label :current_password, 'Old password' %>
<%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %>
<span class="help-block">we need your current password to confirm your changes</span>
</div>
<%= f.submit "Register", class: 'btn btn-primary' %>
<%= f.submit "Update", class: 'btn btn-primary' %>
<% end %>
<!--
<h3>Cancel my account</h3>
......
......@@ -34,3 +34,4 @@ en:
attributes:
user:
fullname: "Full Name"
current_password: 'Old password'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment