示例#1
0
async def add(uid: int, uname: str, password: str, mail: str, regip: str='', realname: str=''):
  """Add a user."""
  validator.check_uname(uname)
  # TODO(iceboy): Filter uname by keywords.
  validator.check_password(password)
  validator.check_mail(mail)

  uname_lower = uname.strip().lower()
  mail_lower = mail.strip().lower()

  for user in builtin.USERS:
    if user['_id'] == uid or user['uname_lower'] == uname_lower or user['mail_lower'] == mail_lower:
      raise error.UserAlreadyExistError(uname)

  salt = pwhash.gen_salt()
  coll = db.coll('user')
  try:
    await coll.insert_one({'_id': uid,
                           'uname': uname,
                           'uname_lower': uname_lower,
                           'realname': realname,
                           'mail': mail,
                           'mail_lower': mail_lower,
                           'salt': salt,
                           'hash': pwhash.hash_vj4(password, salt),
                           'regat': datetime.datetime.utcnow(),
                           'regip': regip,
                           'priv': builtin.DEFAULT_PRIV,
                           'loginat': datetime.datetime.utcnow(),
                           'loginip': regip,
                           'gravatar': mail})
  except errors.DuplicateKeyError:
    raise error.UserAlreadyExistError(uid, uname, mail) from None
示例#2
0
文件: user.py 项目: JoshOY/vj4
async def add(uid: int, uname: str, password: str, mail: str, regip: str = ''):
  """Add a user."""
  validator.check_uname(uname)
  # TODO(iceboy): Filter uname by keywords.
  validator.check_password(password)
  validator.check_mail(mail)

  uname_lower = uname.strip().lower()
  mail_lower = mail.strip().lower()

  for user in builtin.USERS:
    if user['_id'] == uid or user['uname_lower'] == uname_lower or user['mail_lower'] == mail_lower:
      raise error.UserAlreadyExistError(uname)

  salt = pwhash.gen_salt()
  coll = db.Collection('user')
  try:
    await coll.insert({'_id': uid,
                       'uname': uname,
                       'uname_lower': uname_lower,
                       'mail': mail,
                       'mail_lower': mail_lower,
                       'salt': salt,
                       'hash': pwhash.hash_vj4(password, salt),
                       'regat': datetime.datetime.utcnow(),
                       'regip': regip,
                       'roles': {},
                       'priv': builtin.PRIV_USER_PROFILE,
                       'loginat': datetime.datetime.utcnow(),
                       'loginip': regip,
                       'gravatar': mail})
  except errors.DuplicateKeyError:
    raise error.UserAlreadyExistError(uid, uname, mail) from None
示例#3
0
 async def post(self, *, mail: str):
   validator.check_mail(mail)
   if await user.get_by_mail(mail):
     raise error.UserAlreadyExistError(mail)
   rid, _ = await token.add(token.TYPE_REGISTRATION,
                            options.registration_token_expire_seconds,
                            mail=mail)
   await self.send_mail(mail, 'Sign Up', 'user_register_mail.html',
                        url=self.reverse_url('user_register_with_code', code=rid))
   self.render('user_register_mail_sent.html')
示例#4
0
 async def post(self, *, uname: str, password: str, verify_password: str):
     mail = str(uuid.uuid4()) + '@vijos.test'
     validator.check_mail(mail)
     if await user.get_by_mail(mail):
         raise error.UserAlreadyExistError(mail)
     if password != verify_password:
         raise error.VerifyPasswordError()
     uid = await system.inc_user_counter()
     await user.add(uid, uname, password, mail, self.remote_ip)
     self.json_or_redirect('/private-user-list')
示例#5
0
文件: user.py 项目: vijos/vj4
 async def post(self, *, mail: str):
   validator.check_mail(mail)
   if await user.get_by_mail(mail):
     raise error.UserAlreadyExistError(mail)
   rid, _ = await token.add(token.TYPE_REGISTRATION,
                            options.registration_token_expire_seconds,
                            mail=mail)
   await self.send_mail(mail, 'Sign Up', 'user_register_mail.html',
                        url=self.reverse_url('user_register_with_code', code=rid))
   self.render('user_register_mail_sent.html')
示例#6
0
文件: user.py 项目: JoshOY/vj4
 async def post(self, *, mail: str):
   validator.check_mail(mail)
   if await user.get_by_mail(mail):
     raise error.UserAlreadyExistError(mail)
   # TODO(iceboy): rate limit.
   rid, _ = await token.add(token.TYPE_REGISTRATION,
                            options.options.registration_token_expire_seconds,
                            mail=mail)
   content = self.render_html('user_register_mail.html', url_prefix=options.options.url_prefix,
                              url=self.reverse_url('user_register_with_code', code=rid))
   await mailer.send_mail(mail, 'Sign Up - Vijos', content)
   self.render('user_register_mail_sent.html')
示例#7
0
 async def post(self, *, mail: str):
   validator.check_mail(mail)
   udoc = await user.get_by_mail(mail)
   if not udoc:
     raise error.UserNotFoundError(mail)
   rid, _ = await token.add(token.TYPE_LOSTPASS,
                            options.lostpass_token_expire_seconds,
                            uid=udoc['_id'])
   await self.send_mail(mail, 'Lost Password', 'user_lostpass_mail.html',
                        url=self.reverse_url('user_lostpass_with_code', code=rid),
                        uname=udoc['uname'])
   self.render('user_lostpass_mail_sent.html')
示例#8
0
文件: user.py 项目: digideskio/vj4
 async def post(self, *, mail: str):
   validator.check_mail(mail)
   if await user.get_by_mail(mail):
     raise error.UserAlreadyExistError(mail)
   # TODO(iceboy): rate limit.
   rid, _ = await token.add(token.TYPE_REGISTRATION,
                            options.options.registration_token_expire_seconds,
                            mail=mail)
   content = self.render_html('user_register_mail.html', url_prefix=options.options.url_prefix,
                              url=self.reverse_url('user_register_with_code', code=rid))
   await mailer.send_mail(mail, 'Sign Up - Vijos', content)
   self.render('user_register_mail_sent.html')
示例#9
0
文件: user.py 项目: vijos/vj4
 async def post(self, *, mail: str):
   validator.check_mail(mail)
   udoc = await user.get_by_mail(mail)
   if not udoc:
     raise error.UserNotFoundError(mail)
   rid, _ = await token.add(token.TYPE_LOSTPASS,
                            options.lostpass_token_expire_seconds,
                            uid=udoc['_id'])
   await self.send_mail(mail, 'Lost Password', 'user_lostpass_mail.html',
                        url=self.reverse_url('user_lostpass_with_code', code=rid),
                        uname=udoc['uname'])
   self.render('user_lostpass_mail_sent.html')
示例#10
0
文件: home.py 项目: whitefirer/vj4
 async def post_change_mail(self, *, current_password: str, mail: str):
   validator.check_mail(mail)
   udoc, mail_holder_udoc = await asyncio.gather(
     user.check_password_by_uid(self.user['_id'], current_password),
     user.get_by_mail(mail))
   # TODO(twd2): raise other errors.
   if not udoc:
     raise error.CurrentPasswordError(self.user['uname'])
   if mail_holder_udoc:
     raise error.UserAlreadyExistError(mail)
   rid, _ = await token.add(token.TYPE_CHANGEMAIL,
                            options.changemail_token_expire_seconds,
                            uid=udoc['_id'], mail=mail)
   await self.send_mail(mail, 'Change Email', 'user_changemail_mail.html',
                        url=self.reverse_url('user_changemail_with_code', code=rid),
                        uname=udoc['uname'])
   self.render('user_changemail_mail_sent.html')
示例#11
0
文件: home.py 项目: vijos/vj4
 async def post_change_mail(self, *, current_password: str, mail: str):
   validator.check_mail(mail)
   udoc, mail_holder_udoc = await asyncio.gather(
     user.check_password_by_uid(self.user['_id'], current_password),
     user.get_by_mail(mail))
   # TODO(twd2): raise other errors.
   if not udoc:
     raise error.CurrentPasswordError(self.user['uname'])
   if mail_holder_udoc:
     raise error.UserAlreadyExistError(mail)
   rid, _ = await token.add(token.TYPE_CHANGEMAIL,
                            options.changemail_token_expire_seconds,
                            uid=udoc['_id'], mail=mail)
   await self.send_mail(mail, 'Change Email', 'user_changemail_mail.html',
                        url=self.reverse_url('user_changemail_with_code', code=rid),
                        uname=udoc['uname'])
   self.render('user_changemail_mail_sent.html')
示例#12
0
async def set_mail(uid: int, mail: str):
    """Set mail. Returns doc or None."""
    validator.check_mail(mail)
    return await set_by_uid(uid, mail=mail, mail_lower=mail.strip().lower())