Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create
- @user = User.new(params[:user])
- @contact = Contact.new(params[:contact])
- @file = CvFile.new(params[:cv])
- flash[:notice] = ''
- begin
- User.transaction do
- @list = session[:activities]
- @user.group = params['contact_type']
- for i in 0..@list.length - 1
- @contact.entities_sub_categories << EntitiesSubCategory.find(@list[i].id)
- end
- @user.contact = @contact
- @user.save!
- @file.file_type = Integer(Constants.getFileType('cv'))
- if @file.size == nil
- if @contact.cv.strip == ''
- flash.now[:notice] = 'O campo CV tem de ser preenchido ou tem de fornecer um ficheiro'
- raise
- end
- else
- @file.user_id = @user.id
- @file.save!
- end
- end
- rescue Exception => e
- @user.password = ''
- @user.rpassword = ''
- if not @contact.errors.empty?
- @contact.errors.each do |attr, msg|
- flash.now[:notice] += msg.to_s + "\\n"
- end
- end
- if not @user.errors.empty?
- @user.errors.each do |attr, msg|
- flash.now[:notice] += msg.to_s + "\\n"
- end
- end
- if @file.size != nil and not @file.errors.empty?
- flash.now[:notice] += "Ficheiro invalido, certifique-se que inseriu uma extensão\\ncorrecta e que o ficheiro é menor que 1MBytes\\n"
- end
- if flash.now[:notice] == ''
- logger.error("registration error" + e.message)
- flash.now[:notice] = "Ocorreu um erro ao efectuar o registo. Tente mais tarde por favor."
- end
- end
- if flash.now[:notice] != ''
- set_form
- render :action => 'new'
- else
- SendMail.deliver_well_come_message(@contact.name, @user.email, @user.rpassword)
- SendMail.deliver_new_contact_message(@user.id, @contact.updated_at)
- flash[:notice] = "Registo efectuado com sucesso."
- redirect_to :action => 'new'
- end
- end
Add Comment
Please, Sign In to add comment