- if token = UserToken.find_by_token(params[:confirm_string])
- if token.user.active?
- flash[:error] = t('user.confirm.already active')
- redirect_to :action => 'login'
- else
- user = token.user
- user.status = "active"
- user.email_valid = true
- user.save!
- referer = token.referer
- token.destroy
-
- if session[:token]
- token = UserToken.find_by_token(session[:token])
- session.delete(:token)
- else
- token = nil
- end
-
- if token.nil? or token.user != user
- flash[:notice] = t('user.confirm.success')
- redirect_to :action => :login, :referer => referer
- else
- token.destroy
-
- session[:user] = user.id
- cookies.permanent["_osm_username"] = user.display_name
-
- if referer.nil?
- flash[:notice] = t('user.confirm.success') + "<br /><br />" + t('user.confirm.before you start')
- redirect_to :action => :account, :display_name => user.display_name
- else
- flash[:notice] = t('user.confirm.success')
- redirect_to referer
- end
- end
- end
+ token = UserToken.find_by_token(params[:confirm_string])
+ if token && token.user.active?
+ flash[:error] = t('user.confirm.already active')
+ redirect_to :action => 'login'
+ elsif !token || token.expired?
+ flash[:error] = t('user.confirm.unknown token')
+ redirect_to :action => 'confirm'