def join(request): user = Users() user.name = request.POST['name'] user.email = request.POST['email'] user.password = request.POST['password'] user.gender = request.POST['gender'] user.save() return HttpResponseRedirect('/user/joinsuccess')
def _create_user(self, username: str, password: str, userid: int): salt = 'blahfffff{}j349'.format(password) signer = Signer(salt=salt) user = Users() user.user_id = userid user.first_name = 'Billy' user.last_name = 'Bobtest' user.user_name = username user.email = '{}@gmail.com'.format(username) user.about = "This is about me and the things I like" user.last_login_date = timezone.now() user.password_hash = signer.signature(password) user.salt_hash = salt user.save() return user
def post(self, request: HttpRequest): try: request_json = json.loads(request.body.decode('UTF-8')) except json.JSONDecodeError: return JSONResponse.new( code=400, message='request decode error, bad data sent to the server') # these are required keys _user_name = request_json.get('username') _first_name = request_json.get('firstname') _last_name = request_json.get('lastname') _password = request_json.get('password') try: self._check_required_inputs( [_user_name, _first_name, _last_name, _password]) except ValueError as err: return JSONResponse.new(code=400, message='{}'.format(err.args[0])) try: Users.objects.get(user_name__exact=_user_name) except ObjectDoesNotExist: # GOOD, lets create a new user new_user = Users() salt = token_hex(16) signer = Signer(salt=salt) new_user.user_id = uuid4().time_mid new_user.first_name = _first_name new_user.last_name = _last_name new_user.user_name = _user_name new_user.salt_hash = salt new_user.password_hash = signer.signature(_password) new_user.email = request_json.get( 'email', '{}@noemail.set'.format(_user_name)) new_user.about = request_json.get('about', '') new_user.last_login_date = timezone.now() new_user.is_active = True if request_json.get('profilepic') is not None: aws = AWS('snap-life') key_name = '{}.png'.format(request_json.get('profilepic')) url = aws.upload_profile_image(new_user.user_name, key_name) new_user.profile_url = url else: new_user.profile_url = 'static/assets/usericon.png' try: new_user.save() request.session['{}'.format(new_user.user_id)] = True except IntegrityError as err: # if this is because we have a collision with our random numbers # hash, userID etc. re-create them del request.session['{}'.format(new_user.user_id)] return JSONResponse.new( code=500, message='username and email need to be unique') else: return JSONResponse.new( code=400, message='username {} is already taken'.format(_user_name)) return JSONResponse.new(code=200, message='success', userid=new_user.user_id)