Exemple #1
0
def index():
    return response([
        '''
	<!DOCTYPE html>
		<html>
		<head>
			<script
			  src="https://code.jquery.com/jquery-3.3.1.min.js"
			  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
			  crossorigin="anonymous"></script>

		</head>
		<body>
		<input id='username' type='text' />
		<input id='password' type='password' />
		<button id='submit'>Login</button>

			<script>
			$(document).ready(function() {

				$('#submit').click(function() {

					$.ajax({
					  dataType: "json",
					  url: '/login',
					  method: 'POST',
					  contentType: 'application/json',
					  data: JSON.stringify({
						username: $('#username').val(),
						password: $('#password').val()
					  }),
					  success: function() {
						console.log('done', arguments);
						window.location = '/profile';
					  },
					  error: function(data) {
					  	alert('login error');
					  }
					});

				});
			});
			</script>

		</body>
	</html>
	'''.strip()
    ],
                    mimetype='text/html')
Exemple #2
0
def home(x):
    text = f'''
    <!DOCTYPE html>
    <html>
        <head>
        </head>
        <body>
            <center>
            <h1>Welcome to Module</h1>
            <h2>x is {x}</h2>
            <a href='{request.path}/protected'>protected page</a>
            <a href='module.json'>module info</a>
            <hr>
            <a href='..'>back</a>
            </center>
        </body>
    </html
    '''
    return response([text], mimetype='text/html')
Exemple #3
0
def home(x):
    text = f'''
    <!DOCTYPE html>
    <html>
        <head>
        </head>
        <body>
            <center>
            <h1>Welcome to Madness</h1>
            <h2>x is {x}</h2>
            <a href='throw'>raise api exception</a>
            <a href='invalid-route'>404 page</a>
            <a href='relative/path'>relative path!</a>

            <hr>
            <a href='module'>module</a>

            </center>
        </body>
    </html
    '''
    return response([text], mimetype='text/html')
Exemple #4
0
def profile(username):
    return response(
        ['welcome back, ', username, '<br /><a href=/logout>logout</a>'],
        mimetype='text/html')
Exemple #5
0
def crossdomain():
    return response(['from anywhere!'])
Exemple #6
0
def mypath():
    return response(['wow!!'])
Exemple #7
0
def my404():
    return response(['not found!!'])
Exemple #8
0
def response(obj, **kwargs):
    return madness.response(
        [json.dumps(obj)],
        mimetype = 'application/json; charset=utf-8',
        **kwargs
    )
Exemple #9
0
def greet(username):
    return response([f'welcome back, {username}'])