Ejemplo n.º 1
0
def register(request):
    data = {
        "status": "success",
        "message": "",
    }
    if request.method == "POST":
        username = request.POST.get("username")
        user_firstname = request.POST.get("firstname")
        user_lastname = request.POST.get("lastname")
        password = request.POST.get("password")
        email = request.POST.get("email")
        user_gender = request.POST.get("gender")
        if username and user_firstname and user_lastname and password and email and user_gender:
            if not is_valid_email(email):
                data.update({"status": "error", "message": "An invalid email"})
                return HttpResponse(json.dumps(data),
                                    mimetype="application/json")

            flag, acct = Account.objects.new_user(username, user_firstname, user_lastname, password, \
                            email, user_gender)
            if flag:
                user = authenticate(username=username, password=password)
                UserLogin(request, user)
                from tastypie.models import ApiKey
                api = update_api_key(user)
                data.update({
                    "message": "Register successfully",
                    "data": {
                        "api_key": api.key,
                        "username": username,
                    }
                })
            else:
                data.update({
                    "status":
                    "error",
                    "message":
                    "The user with this username already exists"
                })
            return HttpResponse(json.dumps(data), mimetype="application/json")
        else:
            data.update({
                "status":
                "error",
                "message":
                "username or user_firstname or user_lastname or password or email or user_gender is null"
            })
            return HttpResponse(json.dumps(data), mimetype="application/json")
    else:
        data.update({
            "status": "error",
            "message": "only support POST calling"
        })
    return HttpResponse(json.dumps(data), mimetype="application/json")
Ejemplo n.º 2
0
def facebook_connection(request):
    data = {
        "status": "success",
        "message": "",
    }
    if request.method == "POST":
        user_firstname = request.POST.get("firstname")
        user_lastname = request.POST.get("lastname")
        email = request.POST.get("email")
        user_gender = request.POST.get("gender")
        facebook_id = request.POST.get("facebook_id")
        facebook_token = request.POST.get("facebook_token")
        if  user_firstname and user_lastname and email and user_gender and \
                facebook_id and facebook_token:
            if not is_valid_email(email):
                data.update({"status": "error", "message": "An invalid email"})
                return HttpResponse(json.dumps(data),
                                    mimetype="application/json")

            flag, acct = Account.objects.facebook_connection(
                facebook_id, facebook_token, user_firstname, user_lastname,
                email, user_gender)
            if flag:
                user = authenticate(username=facebook_id, password=facebook_id)
                UserLogin(request, user)
                from tastypie.models import ApiKey
                api = update_api_key(user)
                data.update({
                    "message": "Facebook connection successfully",
                    "data": {
                        "api_key": api.key,
                        "username": facebook_id,
                    }
                })
            else:
                data.update({
                    "status": "error",
                    "message": "user's account has issues"
                })
            return HttpResponse(json.dumps(data), mimetype="application/json")
        else:
            data.update({
                "status":
                "error",
                "message":
                "username or user_firstname or user_lastname or password or email or user_gender is null"
            })
            return HttpResponse(json.dumps(data), mimetype="application/json")
    else:
        data.update({
            "status": "error",
            "message": "only support POST calling"
        })
    return HttpResponse(json.dumps(data), mimetype="application/json")
Ejemplo n.º 3
0
    def get_email(self, req, conn, users_id=None):
        email = req.get_param('email')
        if email is None or not is_valid_email(email):
            raise ValidationError('ERR_EMAIL')

        result = db_utils.select(conn,
                                 "users",
                                 columns=("id", ),
                                 where={'email': email.lower()},
                                 limit=1)
        if result and (users_id is None or str(users_id) != str(result[0][0])):
            raise ValidationError('EXISTING_EMAIL')
        return email.lower()
Ejemplo n.º 4
0
def register(request):
    data = {
        "status" : "success",
        "message" : "",
    }
    if request.method == "POST":
        username = request.POST.get("username")
        user_firstname = request.POST.get("firstname")
        user_lastname = request.POST.get("lastname")
        password = request.POST.get("password")
        email = request.POST.get("email")
        user_gender = request.POST.get("gender")
        if username and user_firstname and user_lastname and password and email and user_gender:
            if not is_valid_email(email):
                data.update({
                    "status" : "error",
                    "message" : "An invalid email"
                })
                return HttpResponse(json.dumps(data), mimetype="application/json")

            flag, acct = Account.objects.new_user(username, user_firstname, user_lastname, password, \
                            email, user_gender)
            if flag:
                user = authenticate(username=username, password=password)
                UserLogin(request, user)
                from tastypie.models import ApiKey
                api = update_api_key(user)
                data.update({
                    "message" : "Register successfully",
                    "data" : {
                        "api_key" : api.key,
                        "username" : username,
                    }
                })
            else:
                data.update({
                    "status" : "error",
                    "message" : "The user with this username already exists"
                })
            return HttpResponse(json.dumps(data), mimetype="application/json")
        else:
            data.update({"status" : "error", "message":"username or user_firstname or user_lastname or password or email or user_gender is null"})
            return HttpResponse(json.dumps(data), mimetype="application/json")
    else:
        data.update({"status" : "error", "message":"only support POST calling"})
    return HttpResponse(json.dumps(data), mimetype="application/json")
Ejemplo n.º 5
0
def facebook_connection(request):
    data = {
        "status" : "success",
        "message" : "",
    }
    if request.method == "POST":
        user_firstname = request.POST.get("firstname")
        user_lastname = request.POST.get("lastname")
        email = request.POST.get("email")
        user_gender = request.POST.get("gender")
        facebook_id = request.POST.get("facebook_id")
        facebook_token = request.POST.get("facebook_token")
        if  user_firstname and user_lastname and email and user_gender and \
                facebook_id and facebook_token:
            if not is_valid_email(email):
                data.update({
                    "status" : "error",
                    "message" : "An invalid email"
                })
                return HttpResponse(json.dumps(data), mimetype="application/json")

            flag, acct = Account.objects.facebook_connection(facebook_id, facebook_token, user_firstname, user_lastname, email, user_gender)
            if flag:
                user = authenticate(username=facebook_id, password=facebook_id)
                UserLogin(request, user)
                from tastypie.models import ApiKey
                api = update_api_key(user)
                data.update({
                    "message" : "Facebook connection successfully",
                    "data" : {
                        "api_key" : api.key,
                        "username" : facebook_id,
                    }
                })
            else:
                data.update({
                    "status" : "error",
                    "message" : "user's account has issues"
                })
            return HttpResponse(json.dumps(data), mimetype="application/json")
        else:
            data.update({"status" : "error", "message":"username or user_firstname or user_lastname or password or email or user_gender is null"})
            return HttpResponse(json.dumps(data), mimetype="application/json")
    else:
        data.update({"status" : "error", "message":"only support POST calling"})
    return HttpResponse(json.dumps(data), mimetype="application/json")