The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
Well i am using the points mod and as we frequently have users annoying us with requests to have their username changed i made a neat little function for the points shop mod to have them change their username for XX points ONCE.
I added a new column to the MEMBERS table called "M_CHANGEDNAME" to record if a user already changed his/her name (We only allow ONE change per lifetime).
This replaces the avatar change item in points store, but it could also be used as a standalone mod with some work...
Search for "Case 4 'Use custom avatar" and replace the whole Case with this:
BEFORE the last line add the following:
I made it so the username may not contain blanks or dots (.) at all, if you wanna allow these then replace the last 2 checks with a double blankspace or period as it's in the original registration name check.
I added a new column to the MEMBERS table called "M_CHANGEDNAME" to record if a user already changed his/her name (We only allow ONE change per lifetime).
This replaces the avatar change item in points store, but it could also be used as a standalone mod with some work...
Search for "Case 4 'Use custom avatar" and replace the whole Case with this:
Code:
'=========
Case 4 'Use custom avatar
'actually changed to CHANGE USERNAME
'=========
CreateTable(ItemTitle)
If DoIt <> True Then
Call ShowStats()
Response.Write "<font size=""" & strFooterFontSize & """>You can only change your username ONCE IN YOUR LIFE, so better think twice before doing so.<br> DO NOT use real life names, phone numbers or anything else you might regret later on. <br>Spaces, dots or other special characters are NOT available in your new username.</font><br>"
Response.Write "<table width=""100%"" border=0><tr><td align=center>" & VbNewLine &_
"<b>Current Username: " & strDBNTUserName & "</b><br><br>" & VbNewLine
Response.Write "</td><td align=left>"
Response.Write "<br>New Username: <br><input name=""UserChange"" value=""MyNewUsername"" size=50><br>"
Response.Write "</td></tr></table>" & VbNewLine
Response.Write "<font size=""" & strFooterFontSize & """>You will NOT be able to log in with your OLD username after the change. <br>You will NEVER be able to change your username again after the change.<br> There is NO additional check so TRIPLE check for typos before submitting.</font><br>"
CloseTable(1)
Else
if not IsValidString(trim(Request.Form("UserChange"))) then
Response.Write "<br><br><li>You may not use any of these characters or a space in your Username !#$%^&*()=+{}[]|\;:/?>,<'. </li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
If Request.Form("UserChange") = "" Or len(Request.Form("UserChange")) <=2 Then
Response.Write "<br><br><li>Please enter a valid username. Minimum length is 2 characters.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
End If
'If mid(Request.Form("UserChange"), 1, 7) <> "http://" Then
' strErr = "<li>URL's must start with ""http://"""
'End If
'######check username already in use
strSql = "SELECT M_NAME FROM " & strMemberTablePrefix & "MEMBERS "
strSql = strSql & " WHERE M_NAME = '" & ChkString(Trim(Request.Form("UserChange")), "SQLString") &"'"
set rs = my_Conn.Execute (strSql)
if rs.BOF and rs.EOF then
'## Do Nothing
else
Response.Write "<br><br><li>Error: This Username is already taken.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
rs.close
set rs = nothing
'######end check username in use
'#####check pending
strSql = "SELECT M_NAME FROM " & strMemberTablePrefix & "MEMBERS_PENDING "
strSql = strSql & " WHERE M_NAME = '" & ChkString(Trim(Request.Form("Name")), "SQLString") &"'"
set rs = my_Conn.Execute (strSql)
if rs.BOF and rs.EOF then
'## Do Nothing
else
Response.Write "<br><br><li>Error: This Username is already taken.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
rs.close
set rs = nothing
'####end check pending
'######check username already changed
strSql = "SELECT M_CHANGEDNAME FROM " & strMemberTablePrefix & "MEMBERS "
strSql = strSql & " where MEMBER_ID=" & MemberID
set rs = my_Conn.Execute (strSql)
if rs.BOF and rs.EOF then
'## Do Nothing
'wtf? nothing???
else
if rs("M_CHANGEDNAME") > 0 then
Response.Write "<br><br><li>Error: You already changed your username once. Sorry but we said ONCE IN A LIFETIME and we mean it.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
end if
rs.close
set rs = nothing
'######end check username already changed
If strErr <> "" Then
GoError(strErr)
Else
strSql = "update " & strTablePrefix & "MEMBERS set M_NAME = '" & chkString(Request.Form("UserChange"), "SQLString") & "', " &_
"M_POINTS = M_POINTS -" & ItemCost &_
" where MEMBER_ID=" & MemberID
my_Conn.Execute (strsql)
'update change count
strSql = "update " & strTablePrefix & "MEMBERS set M_CHANGEDNAME = '1'" &_
" where MEMBER_ID=" & MemberID
my_Conn.Execute (strsql)
UpdateItemCount
Response.Write "<br>YOUR USERNAME WAS CHANGED."
Call BackToStore
End If
CloseTable(0)
End If
BEFORE the last line add the following:
Code:
Function IsValidString(sValidate)
Dim sInvalidChars
Dim bTemp
Dim i
' Disallowed characters
sInvalidChars = "!#$%^&*()=+{}[]|\;:/?>,<'"
for i = 1 To Len(sInvalidChars)
if InStr(sValidate, Mid(sInvalidChars, i, 1)) > 0 then bTemp = True
if bTemp then Exit For
next
for i = 1 to Len(sValidate)
if Asc(Mid(sValidate, i, 1)) = 160 then bTemp = True
if bTemp then Exit For
next
' extra checks
' no two consecutive dots or spaces
if not bTemp then
bTemp = InStr(sValidate, ".") > 0
end if
if not bTemp then
bTemp = InStr(sValidate, " ") > 0
end if
if not bTemp then
bTemp = (len(sValidate) <> len(Trim(sValidate)))
end if 'Addition for leading and trailing spaces
' if any of the above are true, invalid string
IsValidString = Not bTemp
End Function
I made it so the username may not contain blanks or dots (.) at all, if you wanna allow these then replace the last 2 checks with a double blankspace or period as it's in the original registration name check.