You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// set_csrf_cookie - generates a CSRF-Token and sets the CSRF-Cookie. It is possible to set the http-only-status of the cookie to false by adding an argument of the HttpOnly-struct like this:
10
+
// `app.set_csrf_cookie(csrf.HttpOnly{false})`
11
+
// If no argument is set, http_only will be set to `true`by default.
panic('Error while trying to generate Csrf-Token: $err')
29
+
}
30
+
out= out + csrf.chars[i..i +1]
31
+
}
32
+
return out
33
+
}
34
+
35
+
// create_cookie - creates the cookie
36
+
fncreate_cookie(h bool) CsrfCookie {
37
+
return CsrfCookie{
38
+
name: csrf.cookie_key
39
+
value: generate()
40
+
path: '/'
41
+
max_age: 0
42
+
secure: true
43
+
http_only: h
44
+
}
45
+
}
46
+
47
+
// get_csrf_token - returns the CSRF-Token that has been set. Make sure that you set one by using `set_csrf_cookie()`. If it's value is empty or no cookie has been generated, the function will thor an error.
48
+
pub fn (mut app App) get_csrf_token() ?string {
49
+
if app.csrf_cookie_value !='' {
50
+
return app.csrf_cookie_value
51
+
} else {
52
+
returnIError(CsrfError{
53
+
m: 'The CSRF-Token-Value is empty. Please check if you have setted a cookie!'
0 commit comments