Beispiel #1
0
    def put(self):
        """
        Request for reset password
        """
        self.reqparse.add_argument(emailArg)
        data = self.reqparse.parse_args()
        user = User.find_by_email(data['email'])
        if not user:
            return "User not found", 404
        if not user.is_activated():
            return "User is not activated yet.", 403
        token = jwt.encode({
            'user_email': data['email']
        }, current_app.config['JWT_SECRET_KEY'],
                           current_app.config['JWT_ALGORITHM']).decode('utf-8')
        user.reset_pw_token = token
        try:
            db.session.add(user)
            db.session.commit()
            send_email('Reset your password on Pystro.', data['email'],
                       'Clique em base_url/?token=' + token)

        except IntegrityError as e:
            db.session.rollback()
            return "Integrity error: " + str(e), 400
Beispiel #2
0
    def post(self):
        """ creates an order """
        self.reqparse.add_argument('items', location='json', type=dict, action='append')
        data = self.reqparse.parse_args()
        try:
            order = Order()
            order.created_by = current_identity.id
            order.state = ORDER_PENDING
            rest = get_current_restaurant()
            order.restaurant_id = rest.id
            db.session.add(order)
            db.session.flush()
            for item in data['items']:
                order_item = OrderItem(order_id=order.id, item_id=int(item['id']),
                                       quantity=int(item['quantity']))
                dbitem = Item.find_by_id(item['id'])
                if dbitem.restaurant_id != order.restaurant_id:
                    raise IntegrityError
                db.session.add(order_item)
            db.session.commit()               
            send_email('New Order on Pystro!',
                       [mng.email for mng in rest.managers],
                       'Nice!')

            return order.serializable(), 201
        except IntegrityError as e:
            db.session.rollback()
            return "Integrity error: " + str(e), 400
def reset_request(request):
    if request.user.is_authenticated:
        dj_auth.logout(request)
        return HttpResponseRedirect(settings.LOGOUT_REDIRECT_URL)
    elif request.method == "POST":
        email = request.POST.get('email', '')
        if email:
            try:
                username = User.objects.filter(email=email)[0].username

                key = request_forgotten(username)
                send_email(email, 'forgotten',
                           'http://127.0.0.1:8000/' + key + '/reset/')

                return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
            except IndexError:
                pass

    return render(request, 'registration/reset.html', {})
Beispiel #4
0
def send(request):
    '''
    html, list, subject
    :param request:
    :return:
    '''
    if not request.user:
        return
    try:
        html = str(request.data['html'])
        list_id = int(request.data['list'])
        subject = str(request.data['subject'])
        elist = List.objects.get(pk=list_id)
    except:
        #TODO All error handling
        raise
    for subscriber in Subscriber.objects.filter(list_id=list_id):
        send_email(subscriber, elist, html, subject)
    return Response({"response": "ok"})
Beispiel #5
0
 def post(self):
     self.reqparse.add_argument(emailArg)
     data = self.reqparse.parse_args()
     if User.find_by_email(data['email']):
         return 'Email already in use.', 203
     user = User(email=data['email'])
     try:
         db.session.add(user)
         db.session.commit()
         activation_token = jwt.encode(
             {
                 'user_email': data['email']
             }, current_app.config['JWT_SECRET_KEY'],
             current_app.config['JWT_ALGORITHM']).decode("utf-8")
         send_email('Complete yor registration on Pystro.', data['email'],
                    'Clique em base_url/?token=' + activation_token)
         return user.serializable(), 201
     except IntegrityError as e:
         db.session.rollback()
         return "Integrity error: " + str(e), 400
def signup(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect('/')
    elif request.method == "POST":
        f = SignupForm(request.POST)
        if f.is_valid():
            f.save()
            username = f.cleaned_data['username']
            email = f.cleaned_data['email']
            User.objects.filter(username=username).update(is_active=False)
            new_user = User.objects.get(username=username)
            prof = UserProfile(user=new_user)

            key = request_activation(username)

            send_email(email, 'activation',
                       'http://127.0.0.1:8000/' + key + '/activate/')

            prof.save()
            return HttpResponseRedirect('/')
    else:
        f = SignupForm()
    return render(request, 'registration/signup.html', {'form': f})