"""Send an email to the address given by sendTo about the new account newAccountEmail."""
fromaddr="From: %s"%supportemail
toaddrs="To: %s"%sendTo
to=toaddrs+"\n"
sub="Subject: Your account created on '%s'\n\n"%cdsname
body="You have created a new account on '%s':\n\n"%cdsname
body+=" Username/Email: %s\n"%newAccountEmail
body+=" Password: %s\n\n"%("*"*len(password))
ifCFG_ACCESS_CONTROL_LEVEL_ACCOUNTS>=1:
body+="This account is awaiting approval by the site administrators and therefore cannot be used as of yet.\nYou will receive an email notification as soon as your account request has been processed.\n"
body+="\n---------------------------------"
body+="\n%s"%cdsname
body+="\nContact: %s"%supportemail
msg=to+sub+body
server=smtplib.SMTP('localhost')
server.set_debuglevel(1)
try:
server.sendmail(fromaddr,toaddrs,msg)
exceptsmtplib.SMTPRecipientsRefused,e:
return0
server.quit()
return1
defget_email(uid):
"""Return email address of the user uid. Return string 'guest' in case
the user is not found."""
out="guest"
res=run_sql("SELECT email FROM user WHERE id=%s",(uid,),1)
ifresandres[0][0]:
out=res[0][0]
returnout
defcreate_userinfobox_body(uid,language="en"):
"""Create user info box body for user UID in language LANGUAGE."""
out=""
returntmpl.tmpl_create_userinfobox(
ln=language,
weburl=weburl,
guest=isGuestUser(uid),
email=get_email(uid),
submitter=isUserSubmitter(uid),
referee=isUserReferee(uid),
admin=isUserAdmin(uid),
)
deflist_registered_users():
"""List all registered users."""
returnrun_sql("SELECT id,email FROM user where email!=''")
deflist_users_in_role(role):
"""List all users of a given role (see table accROLE)
@param role: role of user (string)
@return list of uids
"""
query="""SELECT uacc.id_user
FROM user_accROLE uacc JOIN accROLE acc
ON uacc.id_accROLE=acc.id
WHERE acc.name='%s'"""
res=run_sql(query%MySQLdb.escape_string(role))
ifres:
returnmap(lambdax:int(x[0]),res)
return[]
deflist_users_in_roles(role_list):
"""List all users of given roles (see table accROLE)