Exemplo n.º 1
0
def delete():
    if ml.request.method == 'POST':
        did = ml.request.form.get('cid')  # did -> (delete id)
        for x in user.find({"_id": did}, {
                "Name": 1,
                "Email": 1,
                "Password": 1,
                "_id": 1
        }):
            uid = x['_id']
            name = x['Name']
            email = x['Email']
            password = x['Password']
            User_delete.insert_one({
                "_id": uid,
                "Name": name,
                "Email": email,
                "Password": password
            })
            user.remove({"_id": did}, {
                "Name": 1,
                "Email": 1,
                "Password": 1,
                "_id": 1
            })
            return ml.jsonify({
                "id": uid,
                "message": "Data Delete!",
                "status": "Success"
            })

            # else:
            #     return jsonify({'Message': "IDs Not Found!"})
        # elif did in User_delete.find({"_id":did}, {"_id":1}):
        #     return jsonify({"Message":"User Already Deleted"})
        else:
            return ml.jsonify({
                "message": "This ID doesn't exist!",
                "status": "Error"
            })

    return ml.render_template('delete.html')
Exemplo n.º 2
0
def getuserprofile():
    if ml.request.method == 'POST':
        if ml.request.is_json:
            data = ml.request.get_json()
            userid = data['userID']
        else:
            userid = ml.request.values['userID']
        
        for x in Profile.find({'_id':userid},{'_id':1,'Email':1, 'Name':1, 'Contact_Number':1,'Address':1, 
                                              'City':1, 'State':1,'Country':1, 'ZIP_Code':1}):
            
            return ml.jsonify({'message':'User Data Get Successfully', 
                            'status':'success', 
                            'userProfile':{
                            'userID':x['_id'],'email':x['Email'], 'name':x['Name'], 
                                        'contactNumber':x['Contact_Number'],
                            'address':x['Address'], 'city':x['City'], 'state':x['State'],
                            'country':x['Country'], 'postal_code':x['ZIP_Code']
                            }})
        else:
            return ml.jsonify({'message':'No such UserID found in Profile Data, Check it Again!', 'status':'success'})
            
    return ml.render_template('getuserprofile.html')
Exemplo n.º 3
0
def passupdate():
    if ml.request.method == 'POST':
        if ml.request.is_json:
            data = ml.request.get_json()
            userNewPass = data['newPass']
            userConfirmPass = data['confPass']
            userID = data['userID']
        else:
            userNewPass = ml.request.values['newPass']
            userConfirmPass = ml.request.values['confPass']
            userID = ml.request.values['userID']

        if userNewPass == userConfirmPass:
            user.update_one({'_id': userID},
                            {'$set': {
                                'Password': userNewPass
                            }})
            return ml.jsonify({
                'message': 'password updated successfully',
                'status': 'success',
                'data': {
                    'userNewPass': userConfirmPass,
                    'userID': userID
                }
            })
        else:
            return ml.jsonify({
                'message': "Password didn't match",
                'status': 'failed',
                'data': {
                    'userNewPass': userConfirmPass,
                    'userID': userID
                }
            })

    return ml.render_template('passupdate.html')
Exemplo n.º 4
0
def getbooking():
    if ml.request.method == 'GET':
        result = []
        for i in range(0, timeslotBooking.find({}).count()):
            for x in timeslotBooking.find({}, {
                    "_id": 0,
                    "Name": 1,
                    "Date": 1,
                    "Country": 1,
                    "State": 1
            }):
                result.append({
                    "name": x['Name'],
                    "date": x['Date'],
                    "country": x['Country'],
                    "state": x['State']
                })
            return ml.jsonify({
                "message": "Booking Information",
                "status": "success",
                "Result": result
            })
    else:
        return ml.jsonify({"message": "No Booking Available"})
Exemplo n.º 5
0
def register():
    if ml.request.method == 'POST':
        uemail = ml.request.form.get('email')
        uname = ml.request.form.get('name')
        count = 0
        if uemail in [temp['Email'] for temp in user.find({}, {"Email": 1})]:
            return ml.jsonify({
                "status": "Already used",
                "message": "This Email ID Already Registered Us!"
            })
        elif uemail in [
                temp['Email'] for temp in User_delete.find({}, {"Email": 1})
        ]:
            count += 1
            msg1 = "You are already registered with us and you Deleted your account Previously!"
            msg2 = "Want to Re-activate your account"
            return ml.jsonify({
                "status": "Already used",
                'message': "Already Exist, Reactivate Account!"
            })
            # return jsonify({"Message": })
        else:
            user_count = user.find({}).count()
            delete_count = User_delete.find({}).count()
            result = user_count + delete_count + 1
            fid = "R-WSS"  # auto generated user id with R-WSS (i.e: R-WSS0000001)
            uid = fid + "%07d" % result

            def check():
                global pd, password
                characters = ml.string.ascii_letters + ml.string.digits
                password = "".join(
                    ml.choice(characters) for x in range(ml.randint(8, 8)))
                if ml.re.search("[0-9][a-z][A-Z]", password):
                    pd = password
                    configuration = ml.sib_api_v3_sdk.Configuration()
                    configuration.api_key[
                        'api-key'] = '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'
                    api_instance = ml.sib_api_v3_sdk.SMTPApi(
                        ml.sib_api_v3_sdk.ApiClient(configuration))
                    send_smtp_email = ml.sib_api_v3_sdk.SendSmtpEmail(
                        to=[{
                            "email": uemail,
                            "name": uname
                        }],
                        template_id=13,
                        params={
                            "name": uname,
                            "email": uemail,
                            "pwd": pd
                        },
                        headers={
                            "X-Mailin-custom":
                            "custom_header_1:custom_value_1|custom_header_2:custom_value_2|custom_header_3:custom_value_3",
                            "charset": "iso-8859-1"
                        }
                    )  # SendSmtpEmail | Values to send a transactional email
                    try:
                        # Send a transactional email
                        api_response = api_instance.send_transac_email(
                            send_smtp_email)
                        user.insert_one({
                            "_id": uid,
                            "Name": uname,
                            "Email": uemail,
                            "Password": pd
                        })
                        ml.pprint(api_response)
                    except ml.ApiException as e:
                        print(
                            "Exception when calling SMTPApi->send_transac_email: %s\n"
                            % e)
                    #
                else:
                    return check()

            check()
            return ml.jsonify({
                "status": "Success",
                "message": "Register Successfully",
                "data": {
                    "_id": uid,
                    "name": uname,
                    "email": uemail,
                    "password": password
                }
            })

    return ml.render_template('register.html')
Exemplo n.º 6
0
def reactivate():
    if ml.request.method == 'POST':
        mail = ml.request.form.get('email')
        if mail in [
                temp['Email'] for temp in User_delete.find({}, {"Email": 1})
        ]:
            for x in User_delete.find({"Email": mail}, {
                    "Name": 1,
                    "Email": 1,
                    "Password": 1,
                    "_id": 1
            }):
                uid = x['_id']
                name = x['Name']
                email = x['Email']

                # Code for Password send on User Email
                def check():
                    characters = ml.string.ascii_letters + ml.string.digits
                    password = "".join(
                        ml.choice(characters) for x in range(ml.randint(8, 8)))
                    if ml.re.search("[0-9][a-z][A-Z]", password):
                        global pd
                        pd = password
                        configuration = ml.sib_api_v3_sdk.Configuration()
                        configuration.api_key[
                            'api-key'] = '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'
                        api_instance = ml.sib_api_v3_sdk.SMTPApi(
                            ml.sib_api_v3_sdk.ApiClient(configuration))
                        send_smtp_email = ml.sib_api_v3_sdk.SendSmtpEmail(
                            to=[{
                                "email": email,
                                "name": name
                            }],
                            template_id=14,
                            params={
                                "name": name,
                                "email": email,
                                "pwd": password
                            },
                            headers={
                                "X-Mailin-custom":
                                "custom_header_1:custom_value_1|custom_header_2:custom_value_2|custom_header_3:custom_value_3",
                                "charset": "iso-8859-1"
                            }
                        )  # SendSmtpEmail | Values to send a transactional email
                        try:
                            # Send a transactional email
                            api_response = api_instance.send_transac_email(
                                send_smtp_email)
                            user.insert_one({
                                "_id": uid,
                                "Name": name,
                                "Email": email,
                                "Password": pd
                            })
                            User_delete.remove({"Email": email}, {
                                "Name": 1,
                                "Email": 1,
                                "Password": 1,
                                "_id": 1
                            })
                            ml.pprint(api_response)
                        except ml.ApiException as e:
                            print(
                                "Exception when calling SMTPApi->send_transac_email: %s\n"
                                % e)
                        #
                    else:
                        return check()

                check()
                return ml.jsonify({
                    "status": "Success",
                    "message": "Re-activate Account Successfully",
                    "data": {
                        "_id": uid,
                        "name": name,
                        "email": email,
                        "password": pd
                    }
                })
        else:
            return ml.jsonify({
                "status": "Error",
                "message": "Enter Correct Email ID!"
            })

    msg = "Enter your Email ID for Register Yourself !"
    return ml.render_template('reactivate.html', message=msg)