コード例 #1
0
ファイル: campaign.py プロジェクト: HiddenStrawberry/Anubis
async def attend(campaign_id: str, uid: int, mail: str, tel: str,
                 team_name: str, is_newbie: bool, members: list):
    validator.check_mail(mail)
    validator.check_tel(tel)
    validator.check_team_name(team_name)
    members = list(OrderedSet(members))
    coll = db.Collection('campaign.team')
    try:
        return await coll.find_one_and_update(
            filter={
                'cid': campaign_id,
                'uid': uid
            },
            update={
                '$set': {
                    'mail': mail,
                    'tel': tel,
                    'team_name': team_name,
                    'is_newbie': is_newbie,
                    'members': members
                }
            },
            upsert=True,
            return_document=ReturnDocument.AFTER)
    except errors.DuplicateKeyError:
        raise error.CampaignTeamAlreadyExistError(members, team_name)
コード例 #2
0
    async def post(self,
                   *,
                   cid: str,
                   mail: str,
                   tel: str,
                   team_name: str,
                   is_newbie: bool = False,
                   member_id: str,
                   member_id_number: str):
        validator.check_mail(mail)
        validator.check_tel(tel)
        validator.check_team_name(team_name)
        members = list(
            zip(self.request.POST.getall('member_id'),
                self.request.POST.getall('member_id_number')))
        if len(members) > 3 or len(members) < 1:
            raise error.ValidationError('members')
        cdoc = await campaign.get(cid)
        if not cdoc['is_newbie'] and is_newbie:
            raise error.ValidationError('is_newbie')
        if not self.is_live(cdoc):
            raise error.CampaignNotInTimeError(cdoc['title'])

        for member in members:
            sdoc = await student.check_student_by_id(*member)
            if is_newbie and sdoc['grade'] != datetime.datetime.utcnow().year:
                raise error.StudentIsNotNewbieError(member[0])
        members = [member[0] for member in members]
        await campaign.attend(cid, self.user['_id'], mail, tel, team_name,
                              is_newbie, members)
        redirect_url = self.reverse_url('campaign_teams', cid=cid)
        self.json_or_redirect(redirect_url, redirect=redirect_url)
コード例 #3
0
ファイル: user.py プロジェクト: HiddenStrawberry/Anubis
async def add(uname: str,
              password: str,
              mail: str,
              reg_ip: str = '',
              uid: int = None,
              priv: int = builtin.DEFAULT_PRIV,
              **kwargs):
    # Add a user.
    validator.check_uname(uname)
    # TODO: Filter name by keywords
    validator.check_password(password)
    validator.check_mail(mail)

    uname_lower = uname.strip().lower()
    mail_lower = mail.strip().lower()
    if not uid:
        uid = await system.inc_user_counter()

    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:
        return (await coll.insert_one({
            '_id':
            uid,
            'uname':
            uname,
            'uname_lower':
            uname_lower,
            'mail':
            mail,
            'mail_lower':
            mail_lower,
            'salt':
            salt,
            'hash':
            pwhash.hash_password(password, salt),
            'reg_at':
            datetime.datetime.utcnow(),
            'reg_ip':
            reg_ip,
            'priv':
            priv,
            'login_at':
            datetime.datetime.utcnow(),
            'login_ip':
            reg_ip,
            'gravatar':
            mail,
            **kwargs
        })).inserted_id
    except errors.DuplicateKeyError:
        raise error.UserAlreadyExistError(uid, uname, mail) from None
コード例 #4
0
ファイル: user.py プロジェクト: HiddenStrawberry/Anubis
 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.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')
コード例 #5
0
ファイル: user.py プロジェクト: HiddenStrawberry/Anubis
 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.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')
コード例 #6
0
 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: 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.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')
コード例 #7
0
ファイル: user.py プロジェクト: HiddenStrawberry/Anubis
async def set_mail(uid: int, mail: str):
    validator.check_mail(mail)
    return await set_by_uid(uid, mail=mail, mail_lower=mail.strip().lower())