Exemplo n.º 1
0
def signup(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('homepage'))
    state = None
    if request.method == 'POST':
        password = request.POST.get('password', '')
        repeat_password = request.POST.get('repeat_password', '')
        if password == '' or repeat_password == '':
            state = 'empty'
        elif password != repeat_password:
            state = 'repeat_error'
        else:
            username = request.POST.get('username', '')
            if User.objects.filter(username=username):
                state = 'user_exist'
            else:
                new_user = User.objects.create_user(username=username, password=password,
                                                    email=request.POST.get('email', ''))
                new_user.save()
                new_my_user = MyUser(user=new_user, nickname=request.POST.get('nickname', ''))
                new_my_user.save()
                state = 'success'
    content = {
        'active_menu': 'homepage',
        'state': state,
        'user': None,
    }
    return render(request, 'management/signup.html', content)
Exemplo n.º 2
0
def signup(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index_test'))
    state = None
    if request.method == 'POST':
        password = request.POST.get('password', '')
        repeat_password = request.POST.get('repeat_password', '')
        if password == '' or repeat_password == '':
            state = 'empty'
        elif password != repeat_password:
            state = 'repeat_error'
        else:
            username = request.POST.get('username', '')
            if User.objects.filter(username=username):
                state = 'user_exist'
            else:
                new_user = User.objects.create_user(username=username, password=password,
                                                    email=request.POST.get('email', ''))
                new_user.save()
                new_my_user = MyUser(user=new_user, nickname=request.POST.get('nickname', ''))
                new_my_user.save()
                state = 'success'
    content = {
        'active_menu': 'homepage',
        'state': state,
        'user': None,
    }
    return render(request, 'management/signup.html', content)
Exemplo n.º 3
0
def register(request):
    if request.method == 'POST':
        frm = RegisterForm(request.POST)
        # frm.cleaned_data
        #	print (frm)
        # return HttpResponse("efgsb")
        if frm.is_valid():
            fdata = frm.cleaned_data
            uname = fdata['username']
            name = fdata['name']
            passwd = fdata['password']
            try:
                print uname, passwd
                usr = User(username=uname)
                usr.set_password(passwd)
                usr.save()
            except:
                return HttpResponse("User already exists!")
            myusr = MyUser(user=usr, name=name, t=0)
            myusr.save()

            return render(request, "welcome.html")
        else:
            return HttpResponse("fill all the boxes")
    else:
        return HttpResponse('Nice Try!')
Exemplo n.º 4
0
Arquivo: views.py Projeto: hhktony/ppp
def signup(req):
    if req.session.get('username',''):
        return HttpResponseRedirect('/')
    status = ''
    if req.POST:
        post = req.POST
        passwd = post['passwd']
        repasswd = post['repasswd']
        if passwd != repasswd:
            status = 're_err'
        else:
            if User.objects.filter(username=post['username']):
                status = 'user_exist'
            else:
                newuser = User.objects.create_user(username=post['username'],
                                                   password=post['passwd'],
                                                   email=post['email'],
                                                   )   
                newuser.save()
                new_myuser = MyUser(user=newuser,permission=1)
                new_myuser.save()
                status = 'success'
    content = {'noheader': True, 'status': status}
    return render_to_response('signup.html', content,
                              context_instance=RequestContext(req))
Exemplo n.º 5
0
        def __call__(self, form, field):
            userEmail = form['userEmail'].data
            password = field.data
            # myuser = Myuser.query.filter_by(userEmail = userEmail).first()
            if type(MyUser.login(userEmail)) == str:
                raise ValueError('잘못된 이메일입니다.')

            elif MyUser.login(userEmail)[0] != password:
                print("Wrong Password")
                raise ValueError('잘못된 패스워드입니다.')
Exemplo n.º 6
0
def main(request):
    u = MyUser(username='******', password='******')
    u.save()
    # if request.method != 'POST':
    #     raise Http404('Only POSTs are allowed')
    try:
        username = request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username=username, password=password)
        print user
        # return HttpResponseRedirect('/you-are-logged-in/')
        return render(request, 'polls/main.html', {'project_name': 'Jet\'s Blog'})
    except User.DoesNotExist:
        return Http404('')
Exemplo n.º 7
0
def login(w):
    if w == 'login':
        form = LoginForm()
        mode = 'login'
        if form.validate_on_submit():
            session['userEmail'] = form.data.get('userEmail')
            userEmail = session['userEmail']
            return redirect('/')
    elif w == 'register':
        form = RegisterForm()
        mode = 'register'
        if form.validate_on_submit():
            userEmail = form.data.get('userEmail')
            userName = form.data.get('userName')
            password = form.data.get('password')
            userInfo = {
                'userEmail': userEmail,
                'userName': userName,
                'password': password
            }
            if MyUser.login(userEmail) == 'Wrong Email':
                db.userInfo.insert_one(userInfo)
                return redirect('/user/login')
            else:
                return redirect('/user/register')
    return render_template('login.html', form=form, mode=mode)
Exemplo n.º 8
0
    def post(self):

        user = users.get_current_user()
        if user == None:
            self.redirect('/')
        else:

            current_user = MyUser.get(user.user_id())

            dir_id = self.request.get('dir')

            owner_user, directory, parent = check(current_user.key, dir_id)

            if owner_user and directory and (
                    directory.is_users_dir(current_user.key)
                    or has_write_permission(current_user.key, parent)):

                for upload in self.get_uploads():

                    blobinfo = blobstore.BlobInfo(upload.key())

                    my_file = File(name=blobinfo.filename, blob=upload.key())

                    if not directory.file_exists(my_file.name):
                        directory.files.append(my_file)

                directory.put()

                self.redirect(self.request.referer)
Exemplo n.º 9
0
def hello():
    userEmail = session.get('userEmail', None)
    if userEmail:
        userName = MyUser.login(userEmail)[1]
        return render_template('index.html', userName=userName)

    return render_template('index.html')
Exemplo n.º 10
0
 def obj_create(self, bundle, request=None, **kwargs):
     access_token = bundle.data['access_token']
     strategy = load_strategy(backend='facebook')
     try:
         user = strategy.backend.do_auth(access_token)
         user_id = user['id']
         MyUser.objects(id=user_id).update(set__access_token=access_token)
     except:
         raise BadRequest("Error [1] authenticating user with this provider")
     if user and user.is_active:
         '''Populates friends list via call to facebook API'''
         get_friends(user)
         bundle.obj = user
         rtn_data = MyUser.objects.get(id=user_id)
         bundle.obj.user_id, bundle.obj.access_token = rtn_data.user_id, rtn_data.access_token
         return bundle
     else:
         raise BadRequest("Error [2] authenticating user with this provider")
Exemplo n.º 11
0
def register():
    if request.method == 'POST':
        print(request.method)
        userid = request.form.get('userid')
        username = request.form.get('username')
        password = request.form.get('password')
        re_password = request.form.get('re‐password')

        if (userid and username and password and re_password) and (password == re_password):
             myuser = MyUser()
             myuser.userid = userid
             myuser.username = username
             myuser.password = password

             db.session.add(myuser)
             db.session.commit()
        return redirect('/')

    return render_template('register.html')
Exemplo n.º 12
0
 def get(self):
     user = MyUser.get_by_auth_id('*****@*****.**')
     # self.response.write(user)
     m = Message(
         sent_by=user.key,
         sent_to=user.key,
         subject='Message Subject',
         message='Message Body'
     )
     m.put()
Exemplo n.º 13
0
def adduser(request):  
    adminKey=request.POST.get('adminkey', '')
    username= request.POST.get('username', '')
    password=request.POST.get('password', '')
    repeat_password = request.POST.get('repeat_password', '')
    if adminKey!='iamadministrator':
        return HttpResponse(HTTP_400_BAD_REQUEST)
    else:
        if password == '' or repeat_password == '':
            return HttpResponse(HTTP_400_BAD_REQUEST)
        elif password != repeat_password:
            return HttpResponse(HTTP_400_BAD_REQUEST)
        user=MyUser.objects.filter(username=request.POST.get('username', ''))
        if user is not None:
            return HttpResponse(HTTP_400_BAD_REQUEST)
        else:
            new_user=MyUser(username=request.POST.get('username', '')
                                ,password=request.POST.get('password', ''),
                                permission=request.POST.get('permission', ''))
            new_user.save()
            return HttpResponse(HTTP_200_OK)
Exemplo n.º 14
0
def auth():
    logging.debug("auth: ")    
    user = users.get_current_user()
    logging.debug(user)
    if user:
        logging.debug("auth: User logged in - ")
        #return user
        player = MyUser.gql("WHERE account = :1", user)
        return player.fetch(1)[0]
    else:
        logging.debug("auth: Cannot find a logged in user")
        return None
Exemplo n.º 15
0
def sign_up(request):

    # create serializer from request-data.
    serializer = UserSerializer(data=request.DATA)
    if serializer.is_valid():

        activation_key = MyUser.generate_activation_key()
        serializer.object.activation_key = activation_key

        # saves user data (in both auth-user and my-user models.
        serializer.save()

        # get auth-user model from the serializer.
        # get password from request-data.
        # set password on the model and save.
        user = serializer.object.user
        password = request.DATA.get("user").get("password")
        user.set_password(password)
        user.is_active = False
        user.save()

        # create token for the user
        Token.objects.create(user=user)

        # create an empty talent-profile.
        if serializer.object.type == 'T':
            talent = TalentProfile(my_user=serializer.object, user=user)
            talent.save()
        else:
            casting = CastingProfile(my_user=serializer.object, user=user)
            casting.save()

        # send activation e-mail.
        subject = 'Cast\'M account activation'
        relative_url = "/api/users/activate/%s" % (activation_key, )
        msg = 'Hi %s<br/>' % (user.username, )
        msg += 'Click on the following link to activate your account:<br/>'
        msg += '<a href="%s">Activate</a>' % (request.build_absolute_uri(relative_url), )
        logger.debug(msg)
        send_mail(subject, 'Message', '*****@*****.**', (user.username, ), html_message=msg)

        return Response(message('An activation link is sent to your email address.'), status=HTTP_200_OK)
    else:
        return Response(error_as_text(serializer.errors, HTTP_400_BAD_REQUEST), status=HTTP_400_BAD_REQUEST)
Exemplo n.º 16
0
    def post(self):
        logging.debug("Register:")
        user = users.get_current_user()

        if user:
            player = MyUser.gql("WHERE account = :1", user).fetch(1)
            if len(player) == 0:
                player = MyUser()
                player.account = user
                player.deviceId = self.request.get("deviceId")
                player.put()
                logging.debug("Created new user")
            else:
                logging.debug("Existing user")
            self.response.out.write(json.dumps({'success': 'user registered'}))
        else:
            self.response.out.write(json.dumps({'error': 'No authenticated user'}))
Exemplo n.º 17
0
def check(current_user_key, cwd_id):

    owner = MyUser.get(cwd_id.split('/')[0])
    if owner:

        directory = Directory.get_by_id(cwd_id, owner.key)
        if directory:

            parent = None

            is_shared = directory.is_users_dir(current_user_key)
            if not is_shared:
                parent = directory

                while parent and not is_shared and current_user_key not in parent.lock:
                    is_shared = parent.is_shared_to_me(current_user_key)
                    if not is_shared:
                        parent = parent.get_parent()

            if is_shared:
                return owner, directory, parent

    return None, None, None
Exemplo n.º 18
0
    def get(self, abs_path):

        user = users.get_current_user()
        if user == None:
            self.redirect('/')
        else:

            current_user = MyUser.get(user.user_id())

            abs_path = abs_path.split('/')

            file_index = abs_path[len(abs_path) -
                                  1 if len(abs_path) > 2 else 1]

            abs_path[len(abs_path) - 1] = ''
            abs_path = '/'.join(abs_path)

            owner_user, directory, parent = check(current_user.key, abs_path)

            if file_index and owner_user and directory:
                my_file = directory.files[int(file_index)]
                self.send_blob(my_file.blob, save_as=my_file.name)
            else:
                self.redirect('/')
Exemplo n.º 19
0
 def obj_get_list(self, bundle, **kwargs):
     user_id = bundle.request.GET.get('user_id')
     api_key = bundle.request.GET.get('api_key')
     user = MyUser.objects(user_id=user_id, api_key=api_key)
     return user    
Exemplo n.º 20
0
 def authenticate(self, username=None, password=None): 
     user = MyUser.objects(username=username.lower()).first() 
     if user: 
         if password and user.check_password(password): 
             return user 
     return None 
Exemplo n.º 21
0
 def obj_get_list(self, bundle, **kwargs):
     user_id = bundle.request.GET.get('user_id')
     return MyUser.objects(user_id=user_id)