Activate user on a non-configurated-email-server


(oSiNaReF) #1

Hi.

My server have not configurated email server. It’s possible to activate user via BD or bundle exec rails c production .

I tried this:

u = User.first    
u.active = true    
u.save 

But it doesn’t work. Discourse show me this message:

You can’t log in yet. We previously sent an activation email to you at
XXXXXX@XXXXXXX Please follow the instructions in that email to
activate your account.

In BD, table users show field active of the user to t (true)

Thanks very much


(Aahan Krish) #2

The instructions are here.

  • First create an account.

  • Then run these commands in order:

     cd /var/www/discourse
    
     RAILS_ENV=production bundle exec rails c
    
     # Replace 'myemailaddress@me.com' with your email address
     > u = User.find_by_username_or_email('myemailaddress@me.com')
     > u.activate
     > u.save
    
  • If you also need the user to be the administrator and system user:

     cd /var/www/discourse
    
     RAILS_ENV=production bundle exec rails c
    
     # Replace 'myemailaddress@me.com' with your email address
     > u = User.find_by_username_or_email('myemailaddress@me.com')
     > u.activate
     > u.admin = true
     > u.save
     > SiteSetting.system_username = u.username
    

(Seventoes) #3

There’s also an “Activate” button on the user’s page in the Discourse admin area, which is what I’ve used over the last couple days.


(Régis Hanol) #4

@aahank is right. You should be doing u.activate instead of u.active = true.


(oSiNaReF) #5

Thanks very much. It works


(David Czarnecki) #6

There is a migration from 2013-09-06 that changed the SiteSetting property from system_username to site_contact_username. The last command if you need a user to be the administrator and system user would be:

SiteSetting.site_contact_username = u.username


(Charles Wilmott) #7

I done cd /var/www/discourse

it say’s “No such file or directory”

I’ve "ls"
and there’s no folder there?


(Kane York) #8

Please read the “Host vs Container” section of this post:


(Roadev) #9

How could I use the rails console? I installed discourse with docker …
Thanks.


(Sam Saffron) #10

cd /var/discourse
./launcher enter app
rails c


#11

For some reason this wasn’t working for me (I tried the Rails console method above, for a non-admin user).

I solved it directly in the database, in the email_tokens table, setting confirmed=true.

This is a very old thread - maybe there have been changes since 2015 that require some additional command to achieve the same thing… but anyway I hope this helps someone in the future.