def set_session_current_user(user)
    self.current_user = user
    # Try to reuse existing sessions.
    if session[:authpwn_suid]
      token = Tokens::SessionUid.with_code(session[:authpwn_suid]).first
      if token
        if token.user == user
          token.touch
          return user
        else
          token.destroy
        end
      end
    end
    if user
      session[:authpwn_suid] = Tokens::SessionUid.random_for(user,
          request.remote_ip, request.user_agent || 'N/A').suid
    else
      session.delete :authpwn_suid
    end
  end
def set_session_current_user(user)
    self.current_user = user
    # Try to reuse existing sessions.
    if session[:authpwn_suid]
      token = Tokens::SessionUid.with_code(session[:authpwn_suid]).first
      if token
        if token.user == user
          token.touch
          return user
        else
          token.destroy
        end
      end
    end
    if user
      session[:authpwn_suid] = Tokens::SessionUid.random_for(user,
          request.remote_ip, request.user_agent || 'N/A').suid
    else
      session.delete :authpwn_suid
    end
  end
Sets up the session so that it will authenticate the given user.