Esempio n. 1
0
def user(request, uid):
    if not request.user.profile.flags['dev']:
        raise PermissionDenied()

    user = User.objects.filter(username=uid, profile__test_only=True).first()
    if not user and uid != 'add':
        raise Http404

    if request.method == 'POST':
        first_name = request.POST.get('first_name', 'TEST')
        last_name = request.POST.get('last_name', 'TEST')
        gender = request.POST.get('gender', '*H')
        birthday = request.POST.get('birthday', None)
        if not birthday:
            birthday = None
        test_point = int(request.POST.get('test_point', '0'))
        try:
            kaist_info = json.loads(request.POST.get('kaist_info', ''))
            kaist_id = kaist_info['kaist_uid']
        except:
            kaist_info = {}
            kaist_id = ""

        if not user:
            while True:
                seed = os.urandom(4).encode('hex')
                email = '*****@*****.**' % seed
                if not User.objects.filter(email=email).count():
                    break

            while True:
                username = '******' % os.urandom(8).encode('hex')
                if not User.objects.filter(username=username).count():
                    break

            user = User.objects.create_user(username=username,
                                            first_name=first_name,
                                            last_name=last_name,
                                            email=email,
                                            password=seed)
            profile = UserProfile(user=user, email_authed=True,
                                  test_enabled=True, test_only=True)
            logger.warn('user.create: uid=%s' % username, {'r': request})
        else:
            profile = user.profile
            logger.info('user.modify: uid=%s' % uid, {'r': request})

        user.first_name = first_name
        user.last_name = last_name
        user.save()

        profile.gender = gender
        profile.birthday = birthday
        profile.test_point = test_point
        profile.set_kaist_info({'userid': kaist_id, 'kaist_info': kaist_info})
        profile.save()

        return redirect('/dev/main/')

    return render(request, 'dev/user.html', {'tuser': user})
Esempio n. 2
0
def signup_email(post):
    user_f = UserForm(post)
    raw_email = post.get('email', '')

    if not user_f.is_valid() or not validate_email(raw_email):
        return None

    email = user_f.cleaned_data['email']
    password = user_f.cleaned_data['password']
    first_name = user_f.cleaned_data['first_name']
    last_name = user_f.cleaned_data['last_name']
    while True:
        username = token_hex(10)
        if not User.objects.filter(username=username).count():
            break

    user = User.objects.create_user(username=username,
                                    first_name=first_name,
                                    last_name=last_name,
                                    email=email,
                                    password=password)
    user.save()
    UserProfile(user=user, gender='*H').save()

    token_issue_email_auth(user, newbie=True)
    return user
Esempio n. 3
0
    def handle(self, *args, **options):
        if User.objects.all().count() > 0:
            print('there are existing users - abort')
            return

        user = User.objects.create_user(username='******',
                                        first_name='sysop',
                                        last_name='',
                                        email='*****@*****.**',
                                        password='******')
        user.is_staff = True
        user.is_superuser = True
        user.save()

        user.profile = UserProfile(user=user, email_authed=True)
        user.profile.save()

        print('superuser created as [email protected] / adminadmin')
Esempio n. 4
0
    def handle(self, *args, **options):
        if User.objects.all().count() > 0:
            self.stdout.write('Only use at first setup')
            return

        user = User.objects.create_user(username='******',
                                        first_name='sysop',
                                        last_name='',
                                        email='*****@*****.**',
                                        password='******')
        user.is_staff = True
        user.is_superuser = True
        user.save()

        user.profile = UserProfile(user=user, email_authed=True)
        user.profile.save()

        self.stdout.write(
            'Superuser created with [email protected]/adminadmin')
Esempio n. 5
0
def signup_social(typ, profile):
    while True:
        username = token_hex(10)
        if not User.objects.filter(username=username).count():
            break

    first_name = profile.get('first_name', '')
    last_name = profile.get('last_name', '')

    email = profile.get('email', '')
    if not email:
        email = f'random-{token_hex(6)}@sso.sparcs.org'

    while True:
        if not User.objects.filter(email=email).count():
            break
        email = f'random-{token_hex(6)}@sso.sparcs.org'

    user = User.objects.create_user(username=username,
                                    first_name=first_name,
                                    last_name=last_name,
                                    email=email)
    user.save()

    user.profile = UserProfile(gender=profile.get('gender', '*H'))
    if 'birthday' in profile:
        user.profile.birthday = profile['birthday']

    if typ == 'FB':
        user.profile.facebook_id = profile['userid']
    elif typ == 'TW':
        user.profile.twitter_id = profile['userid']
    elif typ == 'KAIST':
        user.profile.email_authed = email.endswith('@kaist.ac.kr')
        user.profile.save_kaist_info(profile)
    user.profile.save()
    return user
Esempio n. 6
0
def user(request, uid):
    if not request.user.profile.flags['dev']:
        raise PermissionDenied()

    user = User.objects.filter(username=uid, profile__test_only=True).first()
    if not user and uid != 'add':
        raise Http404

    if request.method == 'POST':
        first_name = request.POST.get('first_name', 'TEST')
        last_name = request.POST.get('last_name', 'TEST')
        gender = request.POST.get('gender', '*H')
        birthday = request.POST.get('birthday', None)
        if not birthday:
            birthday = None
        point_test = int(request.POST.get('point_test', '0'))

        try:
            kaist_info = json.loads(request.POST.get('kaist_info', ''))
            kaist_id = kaist_info['kaist_uid']
        except:
            kaist_info = {}
            kaist_id = ""

        if not user:
            while True:
                seed = token_hex(4)
                email = 'test-{}@sso.sparcs.org'.format(seed)
                if not User.objects.filter(email=email).count():
                    break

            while True:
                username = '******'.format(token_hex(8))
                if not User.objects.filter(username=username).count():
                    break

            user = User.objects.create_user(username=username,
                                            first_name=first_name,
                                            last_name=last_name,
                                            email=email,
                                            password=seed)
            profile = UserProfile(user=user,
                                  email_authed=True,
                                  test_enabled=True,
                                  test_only=True)
            logger.warn('user.create: uid=%s' % username, {'r': request})
        else:
            profile = user.profile
            logger.info('user.modify: uid=%s' % uid, {'r': request})

        user.first_name = first_name
        user.last_name = last_name
        user.save()

        profile.gender = gender
        profile.birthday = birthday
        profile.point_test = point_test
        profile.set_kaist_info({'userid': kaist_id, 'kaist_info': kaist_info})
        profile.save()

        return redirect('/dev/main/')

    return render(request, 'dev/user.html', {'tuser': user})
Esempio n. 7
0
def user(request, uid):
    user = User.objects.filter(username=uid, profile__test_only=True).first()
    if not user and uid != 'add':
        raise Http404

    if request.method == 'POST':
        first_name = request.POST.get('first_name', 'TEST')
        last_name = request.POST.get('last_name', 'TEST')

        if not user:
            while True:
                seed = token_hex(4)
                email = f'test-{seed}@sso.sparcs.org'
                if not User.objects.filter(email=email).count():
                    break

            while True:
                username = f'test{token_hex(10)}'
                if not User.objects.filter(username=username).count():
                    break

            user = User.objects.create_user(username=username,
                                            first_name=first_name,
                                            last_name=last_name,
                                            email=email,
                                            password=seed)
            profile = UserProfile(user=user,
                                  email_authed=True,
                                  test_enabled=True,
                                  test_only=True)
        else:
            profile = user.profile

        user.first_name = first_name
        user.last_name = last_name
        user.save()

        birthday = request.POST.get('birthday', None)
        profile.gender = request.POST.get('gender', '*H')
        profile.birthday = birthday if birthday else None
        profile.point_test = int(request.POST.get('point_test', '0'))
        profile.save()

        try:
            kaist_info = json.loads(request.POST.get('kaist_info', ''))
            profile.save_kaist_info({
                'userid': kaist_info['kaist_uid'],
                'kaist_info': kaist_info,
            })
        except Exception:
            pass

        log_msg = 'create' if uid == 'add' else 'update'
        logger.warning(
            f'account.{log_msg}', {
                'r': request,
                'extra': [
                    ('uid', user.username),
                    ('email', user.email),
                ],
            })
        return redirect('/dev/main/')

    return render(request, 'dev/user.html', {'tuser': user})