Creating the default admin user following installation

43 views
Skip to first unread message

siteshell

unread,
Feb 19, 2014, 11:35:07 AM2/19/14
to communi...@googlegroups.com
Hello all,

I'm new to Rails but coming from another language so I understand a little of what is going on. I've been able to successfully set up the default CE site, but have yet to set up email sending so my local "sign-up" attempts are not working as I suspect there is a flag that is set when a user follows a "confirmation" link in an email.

So, I'd like to at least set up a default administrative user - I see that in the source for the CE master there is a db/sample directory - and under that a "users.rb" file - in which there seems to be some methods for setting up the default admin user.

Where/how should I execute this .rb file? Should I put it in with the migrations folder in the gem directory for CE? Should I put it in the migrations folder for the site itself? I'm also thinking ahead for when I deploy this app on Cloudnine and I'll need this file to execute as part of the setup process.

Best,

Peter Bethke

Dan Coutu

unread,
Feb 19, 2014, 2:23:45 PM2/19/14
to communi...@googlegroups.com
Peter, here's a short description of some useful things to know that
will help you:

First of all let introduce the concept of a RAILS_ROOT directory. This
is the top level directory of your Community Engine application. You
will see within it directory names like app, config, db, log, lib,
public and so forth. Set your current working directory to be this
directory from within a terminal (command line) window.

From this directory you can do a number of things via the command line.

So to answer your first question about how to create an admin user type
something like this:

rake community_engine:make_admin email=pdbe...@gmail.com

If you need to activate the user that is easy too. You have two options:
read your log file in the log directory and you will find a copy of the
email message that failed to get sent to you. Copy/paste the URL for
activation from it.

The alternative is to use the rails console. This is a great way to do
quick things or to validate your code theories before committing code
changes to source control.

rails console
irb(main):001:0>

The above starts up the rails console and shows the prompt that you get.
You can now fetch a user record. There are many possible ways but the
basic method is:

u = User.find 1

This will fetch the user record from the DB having id value of 1. That's
probably the new account that you just made. Now you can operate on u to
change the user record. A user record is activated when it has a valid
date/time stored. Here's how you do that:

u.activated_at = DateTime.now

You then need to save your change to the DB like this:

u.save

If in the future you need reset a password on a user account you would
first fetch the account record. In that case you might know the user's
email address and so you could fetch the account like this:

u = User.find_by_email 'pdbe...@gmail.com'

Then you can change their password like this:

u.password = u.password_confirmation = 'the new password'
u.save

I hope this helps!

Dan
> --
> You received this message because you are subscribed to the Google
> Groups "CommunityEngine" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to communityengi...@googlegroups.com.
> To post to this group, send email to communi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/communityengine.
> For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages