title: Creating An Email Authentication With Rails
body: <p>I'm a beginner programmer and am working on an email confirmation. Once users have registered it sends them to a page to enter a confirmation code, which will be sent to the email they used. If submitted correctly it saves the User and logs them in. </p>
  
  <p>I had looked into using Devise and maybe that's the way to go, but it seems I would spend as much time learning someone else's code when I could learn to do it myself. My repo is <a href="https://github.com/latinforadapt/grmbly_app" rel="nofollow">Here</a>.</p>
  
  <p>What I was thinking of coding (in my User controller) is shaping up like this...what do you think? Am I completely off and would be better figuring out Devise/Authlogic or am I on the right track? I'm using rails 3.1. Any help would be much appreciated.  Thanks in advance.</p>
  
  <pre><code>def   confirmation_code_to_register(string)
    @confirmation_code = #random number
  end
  
  def create_start
    @user = User.new(params[:user])
    #send email with @confirmation_code via ActionMailer
    redirect_to page_to_enter_confirmation_code
    email_authenticate
  end
  
  
  def email_authenticate
    if #confirmation code user enters == @confirmation_code
      create_finish
    else
      #sorry, you entered the wrong confirmation code. 
    end
  end
  
  def create_finish
    if @user.save
      sign_in @user
      flash[:success] = "Welcome to the Site"
      redirect_to @user
    else
      @title = "Sign Up"
      render 'new'
    end
  end
  </code></pre>