<commit_before>package views

import (
	"crypto/md5"
	"crypto/sha256"
	"fmt"
	"github.com/backslashed/gopherblog/models"
	"net/http"
)

func ViewLogin(w http.ResponseWriter, r *http.Request) {
	tplData := struct{ Msg, ReturnUrl string }{
		ReturnUrl: r.URL.Query().Get("return"),
	}

	if r.Method == "POST" {
		md5pass := fmt.Sprintf("%x", md5.Sum([]byte(r.FormValue("password"))))

		user := &models.User{
			Email:    r.FormValue("login"),
			Password: <PASSWORD>,
		}

		if user.LoginCorrect() {
			redirect := r.FormValue("redirectUrl")
			if len(redirect) == 0 {
				redirect = "/"
			}

			origin := []byte(r.RemoteAddr + r.UserAgent())
			val := fmt.Sprintf("%d:%x", user.Id, sha256.Sum256(origin))
			http.SetCookie(w, &http.Cookie{
				Name:  "auth",
				Value: val,
			})

			http.Redirect(w, r, redirect, 307)
		}

		tplData.Msg = "Invalid login and password combination."<commit_msg>Simplification of the nation for the next generation<commit_after>package views

import (
	"crypto/md5"
	"crypto/sha256"
	"fmt"
	"github.com/backslashed/gopherblog/models"
	"net/http"
)

func ViewLogin(w http.ResponseWriter, r *http.Request) {
	tplData := struct{ Msg, ReturnUrl string }{
		ReturnUrl: r.URL.Query().Get("return"),
	}

	if r.Method == "POST" {
		md5pass := fmt.Sprintf("%x", md5.Sum([]byte(r.FormValue("password"))))

		user := &models.User{
			Email:    r.FormValue("login"),
			Password: <PASSWORD>,
		}

		if user.LoginCorrect() {
			origin := []byte(r.RemoteAddr + r.UserAgent())
			val := fmt.Sprintf("%d:%x", user.Id, sha256.Sum256(origin))
			http.SetCookie(w, &http.Cookie{
				Name:  "auth",
				Value: val,
			})

			http.Redirect(w, r, r.FormValue("redirectUrl"), 307)
		}

		tplData.Msg = "Invalid login and password combination."
{'fraction_non_alphanumeric': 0.1814033086138049, 'fraction_numerical': 0.017683970336565887, 'mean_word_length': 3.779291553133515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6386794', 'n_tokens_mistral': 730, 'n_tokens_neox': 638, 'n_words': 126}