コード例 #1
0
def register(request):
    if request.method == 'POST':
        uform = UserRegisterForm(request.POST)
        pform = ProfileRegisterForm(request.POST)
        if uform.is_valid() and pform.is_valid():
            new_username = uform.cleaned_data['username']
            uform.save()
            new_user = User.objects.get(username=new_username)
            pdata = pform.cleaned_data
            account = Profile(user=new_user,
                              fname=pdata['fname'],
                              lname=pdata['lname'],
                              number=pdata['number'],
                              address=pdata['address'],
                              gender=pdata['gender'],
                              graduation_year=getGrad(pdata['grade']),
                              section=pdata['section'],
                              code=pdata['code'],
                              medium=pdata['medium'],
                              shift=pdata['shift'],
                              form_teacher=pdata['form_teacher'])
            account.save()
            messages.success(
                request,
                "Your account has been successfully created. You can now log in."
            )
            return redirect('login')
            # add a message saying ur account has been created
            # redirect to the login page
    else:
        uform = UserRegisterForm()
        pform = ProfileRegisterForm()

    context = {'uform': uform, 'pform': pform}
    return render(request, 'frontend/register.html', context)
コード例 #2
0
def signup(request):
    if request.user.is_authenticated:
        return redirect('/')
    if request.method == 'POST':
        form = Sign_up_form(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            profile = Profile(user=user)
            profile.save()
            login(request, user)
            return redirect('/')
    else:
        form = Sign_up_form()
    return render(request, 'registration/signup.html', {'form': form})
コード例 #3
0
ファイル: views.py プロジェクト: CS130-W20/team-B6
def signup(request):
    required_data = ["username", "password", "firstname", "lastname"]
    data = json.loads(request.body)
    for key in required_data:
        if key not in data:
            return HttpResponse("Missing data to create user.", status=401)
    if User.objects.filter(username=data["username"]):
        return HttpResponse("Username already in use.", status=409)
    try:
        validate_password(data["password"])
    except:
        return HttpResponse("Password is not strong enough.", status=400)
    new_user = User(username=data["username"])
    new_user.set_password(data["password"])
    new_user.save()
    new_profile = Profile(first_name=data["firstname"],
                          last_name=data["lastname"])
    new_profile.user = new_user
    new_profile.save()
    return HttpResponse("User created successfully.")
コード例 #4
0
ファイル: profile.py プロジェクト: bovitobo/bo
def createProfile(parent_user = None, params = None):
    if params == None:
        logger.error('No params specified')
        raise Exception('No params specified')

    try:
        # check required param company_name
        if 'p_company_name' not in params:
            raise Exception('Company Name is Required')
        else:
            company_name = replace(params['p_company_name']).strip()
            if company_name == '':
                raise Exception('Company Name is Required')
                
        if parent_user == None:
            """Create User"""
            # check not required param username
            if 'username' not in params:
                username = company_name.strip(' ') + '_' + str(random.randint(1,9999))
            else:
                username = replace(params['username']).strip(' ') # remove all spaces, even between words
                if username == '':
                    username = company_name.replace(" ", "") # remove all spaces, even between words
                    username = username + '_' + str(random.randint(1,9999))

            # check param password
            if 'password' not in params:
                password = '******' # 'password'
            else:
                password = replace(params['password']).strip()
                if password == None or password.strip() == '':
                    password = '******'


            if User.objects.filter(username=username).exists():
                raise Exception("User with User Name: '" + username + "' already Exist, Please choose another User Name")

            user = User.objects.create(username=username, password=password, date_joined=datetime.now())




        """Create Profile"""
        if parent_user == None:
            parent_user = user
        else:
            user = parent_user

        # check not requried params
        if 'email' not in params: email = ''
        else: email = replace(params['email']).strip()

        if 'description' not in params: description = ''
        else: description = replace(params['description']).strip()

        if 'first_name' not in params: first_name = ''
        else: first_name = replace(params['first_name']).strip()

        if 'last_name' not in params: last_name = ''
        else: last_name = replace(params['last_name']).strip()

        if 'phone_num_1' not in params: phone_num_1 = ''
        else: phone_num_1 = replace(params['phone_num_1']).strip()

        if 'phone_num_2' not in params: phone_num_2 = ''
        else: phone_num_2 = replace(params['phone_num_2']).strip()

        if 'web_page' not in params: web_page = ''
        else: web_page = replace(params['web_page']).strip()

        if 'fax_num' not in params: fax_num = ''
        else: fax_num = replace(params['fax_num']).strip()

        if 'address_1' not in params: address_1 = ''
        else: address_1 = replace(params['address_1']).strip()

        if 'address_2' not in params: address_2 = ''
        else: address_2 = replace(params['address_2']).strip()

        if 'address_3' not in params: address_3 = ''
        else: address_3 = replace(params['address_3']).strip()

        if 'address_4' not in params: address_4 = ''
        else: address_4 = replace(params['address_4']).strip()

        if 'address_5' not in params: address_5 = ''
        else: address_5 = replace(params['address_5']).strip()

        if 'mobile_phone_num' not in params: mobile_phone_num = ''
        else: mobile_phone_num = replace(params['mobile_phone_num']).strip()

        if 'notes' not in params: notes = ''
        else: notes = replace(params['notes']).strip()

        if 'category' not in params: category = ''
        else: category = replace(params['category']).strip()

        # check required param role
        if 'role' not in params:
            raise Exception('role is Required')
        else:
            role = replace(params['role']).strip()
            if role.strip() == '':
                raise Exception('role is Required')

        # create default Settings for this profile
        settings = Settings.createDefaultSettings(user)

        newProfile = Profile(                       \
            user = user                             \
            ,parent_user = parent_user              \
            ,settings = settings                    \
            ,role = role                            \
            ,company_name = company_name            \
            ,email = email                          \
            ,description = description              \
            ,first_name = first_name                \
            ,last_name = last_name                  \
            ,phone_num_1 = phone_num_1              \
            ,phone_num_2 = phone_num_2              \
            ,web_page = web_page                    \
            ,fax_num = fax_num                      \
            ,address_1 = address_1                  \
            ,address_2 = address_2                  \
            ,address_3 = address_3                  \
            ,address_4 = address_4                  \
            ,address_5 = address_5                  \
            ,mobile_phone_num = mobile_phone_num    \
            ,notes = notes                          \
            ,category = category                    \
        )

        newProfile.save()


        return newProfile

    except Exception, err:
        logger.error(err)
        raise err # throw error farther to caller