This `if/else` block could be extracted to a helper method named `login`

```
def login(user, error_message, failure_location)
  if user && user.persisted?
    session[:user_id] = new_user.id
    redirect '/'
  else
    flash[:error] = error_message
    redirect(failure_location)
  end
end
```