"""Send an email to the address given by sendTo about the new account newAccountEmail."""
_=gettext_set_language(ln)
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:
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
defget_email_from_username(username):
"""Return email address of the user corresponding to USERNAME.
The username may be either nickname or email. Return USERNAME
untouched if not found in the database or if found several
matching entries.
"""
out=username
res=run_sql("SELECT email FROM user WHERE email=%s",(username,),1)+ \
run_sql("SELECT email FROM user WHERE nickname=%s",(username,),1)
ifresandlen(res)==1:
out=res[0][0]
returnout
#def get_password(uid):
#"""Return password of the user uid. Return None in case
#the user is not found."""
#out = None
#res = run_sql("SELECT password FROM user WHERE id=%s", (uid,), 1)
#if res and res[0][0] != None:
#out = res[0][0]
#return out
defget_nickname(uid):
"""Return nickname of the user uid. Return None in case
the user is not found."""
out=None
res=run_sql("SELECT nickname FROM user WHERE id=%s",(uid,),1)
ifresandres[0][0]:
out=res[0][0]
returnout
defget_nickname_or_email(uid):
"""Return nickname (preferred) or the email address of the user uid.
Return string 'guest' in case the user is not found."""
out="guest"
res=run_sql("SELECT nickname, email FROM user WHERE id=%s",(uid,),1)