basic authentication
This commit is contained in:
18
it1/js/auth.js
Normal file
18
it1/js/auth.js
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
var signin = function() {
|
||||
firebase.auth()
|
||||
.signInWithEmailAndPassword($('#mail')[0].value, $('#password')[0].value)
|
||||
.then(function() {
|
||||
document.location.href = "/it1/"
|
||||
}).catch(function(error) {
|
||||
$('#status').html('<h3>Kunne ikke logge inn som '+$('#mail')[0].value+'!</h3><p>'+error.code+': '+error.message+'</p>')
|
||||
$('#status').css('color', 'red')
|
||||
})
|
||||
}
|
||||
|
||||
$(document).keydown(function(e) {
|
||||
if (e.which == 13){
|
||||
$("#login").click()
|
||||
}
|
||||
})
|
||||
|
10
it1/js/init-firebase.js
Normal file
10
it1/js/init-firebase.js
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
firebase.initializeApp({
|
||||
apiKey: "AIzaSyAhU3F-De17VAsUgpRjj25f48QiXycorD4",
|
||||
authDomain: "it1-heimdal-vgs.firebaseapp.com",
|
||||
databaseURL: "https://it1-heimdal-vgs.firebaseio.com",
|
||||
projectId: "it1-heimdal-vgs",
|
||||
storageBucket: "it1-heimdal-vgs.appspot.com",
|
||||
messagingSenderId: "206703382262",
|
||||
appId: "1:206703382262:web:be48f32d11a15fa28f26d7"
|
||||
})
|
43
it1/js/navbar.js
Normal file
43
it1/js/navbar.js
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
$('#navbar').parent().html(`
|
||||
<nav class="navbar navbar-expand-sm bg-dark navbar-dark" id="navbar">
|
||||
<a class="navbar-brand" href="/it1/">IT1 firebase stuff</a>
|
||||
<!-- <ul class="navbar-nav">
|
||||
<li class="nav-item right">
|
||||
<a class="nav-link" href="/it1/about.html">About</a>
|
||||
</li>
|
||||
</ul> -->
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<!-- <li class="nav-item right" id="register-btn">
|
||||
<a class="nav-link" href="/register">Register</a>
|
||||
</li> -->
|
||||
<li class="nav-item right">
|
||||
<a class="nav-link" id="login-btn" href="/it1/bruker/"></a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>`)
|
||||
|
||||
var signout = function() {
|
||||
firebase.auth()
|
||||
.signOut()
|
||||
.then(function() {
|
||||
document.location.href = '/it1/'
|
||||
}).catch(function(error) {
|
||||
alert('could not log out: '+error.message)
|
||||
})
|
||||
}
|
||||
|
||||
firebase.auth().onAuthStateChanged(function(user) {
|
||||
if (user) {
|
||||
$('#login-btn').attr('href', 'javascript: signout()')
|
||||
$('#login-btn').html('Logout')
|
||||
} else {
|
||||
$('#login-btn').attr('href', '/it1/bruker/login')
|
||||
$('#login-btn').html('Login')
|
||||
}
|
||||
})
|
||||
|
||||
for (var i = 0; i < $('#navbar').children().length; i++) {
|
||||
$('#navbar').children().css('color', 'springgreen')
|
||||
}
|
||||
|
Reference in New Issue
Block a user