Projekt

Obecné

Profil

Stáhnout (2.6 KB) Statistiky
| Větev: | Revize:
1
<div id="login-modal" class="modal fade" role="dialog">
2
    <div class="modal-dialog modal-dialog-centered" role="document">
3
        <div class="modal-content">
4
            <div class="modal-header">
5
                <h4 class="modal-title">Přihlásit se</h4>
6
                <button type="button" class="close" data-dismiss="modal">&times;</button>
7
            </div>
8
            <div class="modal-body">
9
                <div class="container">
10
                    <div class="row">
11
                        <div class="col-xs-12 col-sm-5">
12
                            <label for="nick">Přihlašovací jméno</label>
13
                        </div>
14
                        <div class="col-xs-12 col-sm-7">
15
                            <input type="text" id="nick">
16
                        </div>
17
                    </div>
18
                    <div class="row">
19
                        <div class="col-xs-12 col-sm-5">
20
                            <label for="password">Heslo</label>
21
                        </div>
22
                        <div class="col-xs-12 col-sm-7">
23
                            <input type="password" id="password">
24
                        </div>
25
                    </div>
26
                </div>
27
            </div>
28
            <div class="modal-footer">
29
                <button type="button" class="btn btn-default" data-dismiss="modal" onclick="login()">Přihlásit se</button>
30
                <button type="button" class="btn btn-default" data-dismiss="modal" onclick="register()">Zavřít</button>
31
            </div>
32
        </div>
33
    </div>
34
</div>
35

    
36
<script>
37
    function register(){
38
        var data = new FormData();
39
        data.append("user", 'partyboypajda');
40
        data.append("password", 'partypass');
41
        data.append("role", 'partymanager');
42
        let xhr = new XMLHttpRequest();
43
        xhr.open("POST", "controller/RegistrationController.php");
44
        xhr.send(data);
45
    }
46

    
47
    function login () {
48
        var data = new FormData();
49
        data.append("username", document.getElementById('nick').value);
50
        data.append("password", document.getElementById('password').value);
51
        var xhr = new XMLHttpRequest();
52
        xhr.open("POST", "controller/LoginController.php");
53
        xhr.onload = function(){
54
            if(this.response == 'Incorrect username and/or password!'){ //login was not successful, show modal
55
                $("#invalidlogin-modal").modal("show");
56
            }else{ //login was successful, refresh page to apply changes in visible items
57
               window.location.href = window.location.href;
58
            }
59
        };
60
        xhr.send(data);
61

    
62
        return false;
63
    }
64

    
65
</script>
(5-5/8)