Is there users_controller create hook?
Added by Xiang Zhai over 14 years ago
I want to extend the users_controller create function.
For example, when register_by_someone or register_manually_by_administrator (see app/controllers/account_controller.rb register function), I want to INSERT INTO other_webapp_user_table with redmine users original data info.
PS: because redmine use Digest::SHA1.hexdigest to generate hashed_password, it is better to get redmine original data.
Please someone give me some advice, thanks a lot!
Replies (5)
RE: Is there users_controller create hook?
-
Added by Xiang Zhai over 14 years ago
I had not found such hook now, perhaps redmine supported it but I did not know it yet!
So I directly modified the redmine source code to insert into testlink_users table when created new user in redmine.
Index: users_controller.rb
===================================================================
--- users_controller.rb (revision 3)
+++ users_controller.rb (working copy)@ -94,6 +94,14 @
@user.login = params[:user][:login]
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
+ # TODO: INSERT INTO testlink_users TABLE
+ db = Mysql.real_connect("localhost", "root", "123456", "testlink")
+ db.query(sprintf("INSERT INTO users(login, password, role_id, email, first, \
+ last, locale, active) VALUES",
+ @user.login, Digest::MD5.hexdigest(@user.password), 7, @user.mail,
+ @user.firstname, @user.lastname, 'zh_CN', 1))
+ db.close()
+
# TODO: Similar to My#account
@user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
Also please someone give me some advice about users_controller create hook, thanks a lot!
RE: Is there users_controller create hook?
-
Added by Etienne Massip over 14 years ago
Hooks are listed in wiki.
RE: Is there users_controller create hook?
-
Added by Xiang Zhai over 14 years ago
yup, there is the hook list indeed, but perhaps no user creation hook available.
RE: Is there users_controller create hook? or update
-
Added by Xiang Zhai over 14 years ago
About update stuff.
@ -129,6 +137,7 @
def edit
auth_sources = AuthSource.find(:all)@m_edit_user_login = @user.login
@membership ||= Member.new
+
end
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
@ -141,6 +150,20 @
@user.safe_attributes = params[:user]
# Was the account actived ? (do it before User#save clears the change)
was_activated = (user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
+
+ # TODO: UPDATE testlink_users TABLE
+ db = Mysql.real_connect("localhost", "root", "123456", "testlink")
+ sql = sprintf("UPDATE users SET login = '%s', role_id = %d, email = '%s', \
+ first = '%s', last = '%s', active = %d",
+ @user.login, @user.admin ? 8 : 7, @user.mail, @user.firstname,
+ @user.lastname, @user.status ? 1 : 0)
+ if "" != @user.password
+ sql += sprintf(", password = '%s'", Digest::MD5.hexdigest(@user.password))
+ end
+ sql += sprintf(" WHERE login = '%s'", @m_edit_user_login)
+ db.query(sql)
+ db.close()
+
# TODO: Similar to My#account
user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
@ -211,7 +234,9 @@
end
private
-
@@m_edit_user_login = ""
+
def find_user
if params[:id] == 'current'
require_login || return
RE: Is there users_controller create hook?
-
Added by Etienne Massip over 14 years ago
You should fill a Feature Request / a Patch in tracker if it does not exist already =)