<commit_before>package pitchforkui

import (
	"errors"
	"strconv"

	"trident.li/keyval"
	pf "trident.li/pitchfork/lib"
)

func h_user_username(cui PfUI) {
	var msg string
	var err error

	user := cui.SelectedUser()

	if cui.IsPOST() {
		var confirmed_s string
		confirmed_s, err = cui.FormValue("confirm")
		newname, err2 := cui.FormValue("username")

		confirmed := pf.IsTrue(confirmed_s)

		if err == nil && err2 == nil && confirmed && newname != "" {
			if newname == user.GetUserName() {
				err = errors.New("Name did not change")
			} else {
				cmd := "user set ident"
				arg := []string{user.GetUserName(), newname}
				msg, err = cui.HandleCmd(cmd, arg)

				if err == nil {
					/* Logout as identity changed */
					cui.Logout()

					/* Redirect to Login page */
					cui.SetRedirect("/login/", StatusSeeOther)
					return
				}
			}
		}
	}

	var errmsg = ""

	if err != nil {
		/* Failed */
		errmsg = err.Error()
	} else {
		/* Success */
	}

	type np struct {
		UserName string `label:"New username" pfreq:"yes" hint:"The new username"`
		Confirm  bool   `label:"Confirm username change" pfreq:"yes" hint:"Confirm username change"`
		Button   string `label:"Change username" pftype:"submit"`
	}

	/* Output the page */
	type Page struct {
		*PfPage
		Opt     np
		Message string
		Error   string
	}

	p := Page{cui.Page_def(), np{user.GetUserName(), false, ""}, msg, errmsg}
	cui.Page_show("user/username.tmpl", p)
}

func h_user_password(cui PfUI) {
	var msg string
	var err error

	user := cui.SelectedUser()

	if cui.IsPOST() {
		var passc string
		passc, err = cui.FormValue("passwordC")
		pass1, err2 := cui.FormValue("password1")
		pass2, err3 := cui.FormValue("password2")

		if err == nil && err2 == nil && err3 == nil && passc != "" && pass1 != "" && pass1 == pass2 {
			cmd := "user password set"
			arg := []string{"portal", user.GetUserName(), passc, pass1}
			msg, err = cui.HandleCmd(cmd, arg)

			nuser := cui.SelectedUser()

			if nuser != user {
				/* Logout as password changed */
				cui.Logout()<commit_msg>chage arg order for user password change.<commit_after>package pitchforkui

import (
	"errors"
	"strconv"

	"trident.li/keyval"
	pf "trident.li/pitchfork/lib"
)

func h_user_username(cui PfUI) {
	var msg string
	var err error

	user := cui.SelectedUser()

	if cui.IsPOST() {
		var confirmed_s string
		confirmed_s, err = cui.FormValue("confirm")
		newname, err2 := cui.FormValue("username")

		confirmed := pf.IsTrue(confirmed_s)

		if err == nil && err2 == nil && confirmed && newname != "" {
			if newname == user.GetUserName() {
				err = errors.New("Name did not change")
			} else {
				cmd := "user set ident"
				arg := []string{user.GetUserName(), newname}
				msg, err = cui.HandleCmd(cmd, arg)

				if err == nil {
					/* Logout as identity changed */
					cui.Logout()

					/* Redirect to Login page */
					cui.SetRedirect("/login/", StatusSeeOther)
					return
				}
			}
		}
	}

	var errmsg = ""

	if err != nil {
		/* Failed */
		errmsg = err.Error()
	} else {
		/* Success */
	}

	type np struct {
		UserName string `label:"New username" pfreq:"yes" hint:"The new username"`
		Confirm  bool   `label:"Confirm username change" pfreq:"yes" hint:"Confirm username change"`
		Button   string `label:"Change username" pftype:"submit"`
	}

	/* Output the page */
	type Page struct {
		*PfPage
		Opt     np
		Message string
		Error   string
	}

	p := Page{cui.Page_def(), np{user.GetUserName(), false, ""}, msg, errmsg}
	cui.Page_show("user/username.tmpl", p)
}

func h_user_password(cui PfUI) {
	var msg string
	var err error

	user := cui.SelectedUser()

	if cui.IsPOST() {
		var passc string
		passc, err = cui.FormValue("passwordC")
		pass1, err2 := cui.FormValue("password1")
		pass2, err3 := cui.FormValue("password2")

		if err == nil && err2 == nil && err3 == nil && passc != "" && pass1 != "" && pass1 == pass2 {
			cmd := "user password set"
			arg := []string{"portal", user.GetUserName(), pass1, passc}
			msg, err = cui.HandleCmd(cmd, arg)

			nuser := cui.SelectedUser()

			if nuser != user {
				/* Logout as password changed */
				cui.Logout()
{'fraction_non_alphanumeric': 0.15281827016520894, 'fraction_numerical': 0.006802721088435374, 'mean_word_length': 3.1335341365461846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5056582', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1427, 'n_words': 383}