📄 yetanotherforumuserprovider.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using ScrewTurn.Wiki.PluginFramework;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
namespace ExtentionsByTeddy
{
public class YetAnotherForumUserProvider : IUsersStorageProvider
{
private ComponentInformation info = new ComponentInformation("YetAnotherForum.NET Users Provider", "5JBB.COM", "http://5jbb.com");
private IHost host;
private string connectionString;
#region IUsersStorageProvider Members
public bool TestAccount(UserInfo user, string password)
{
string hashPassword = FormsAuthentication.HashPasswordForStoringInConfigFile( password.ToString(), "md5" );
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select [Password] from yaf_User where [Name] = @Name";
SqlParameter p1 = cmd.CreateParameter();
p1.ParameterName = "@Name";
p1.SqlDbType = SqlDbType.NVarChar;
p1.Size = 32;
p1.Value = user.Username;
cmd.Parameters.Add(p1);
string userPassword = cmd.ExecuteScalar().ToString();
conn.Close();
return userPassword.Equals(hashPassword);
}
}
public UserInfo[] AllUsers
{
get
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select [Name], [Email], [Flags], [Joined] from yaf_User";
using (IDataReader reader = cmd.ExecuteReader())
{
List<UserInfo> users = new List<UserInfo>();
while (reader.Read())
{
UserInfo user = new UserInfo(
reader.GetString(0), //username
reader.GetString(1), //email
(reader.GetInt32(2) & 2) == 2, //active
reader.GetDateTime(3), //datetime
false, //admin
this
);
users.Add(user);
}
reader.Close();
return users.ToArray();
}
conn.Close();
}
return null;
}
}
public UserInfo AddUser(string username, string password, string email, bool active, DateTime dateTime, bool admin)
{
throw new Exception("The method or operation is not implemented.");
}
public UserInfo SetUserActivationStatus(UserInfo user, bool active)
{
throw new Exception("The method or operation is not implemented.");
}
public UserInfo SetUserAdministrationStatus(UserInfo user, bool admin)
{
throw new Exception("The method or operation is not implemented.");
}
public bool RemoveUser(UserInfo user)
{
throw new Exception("The method or operation is not implemented.");
}
public UserInfo ChangeEmail(UserInfo user, string newEmail)
{
throw new Exception("The method or operation is not implemented.");
}
public UserInfo ChangePassword(UserInfo user, string newPassword)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region IStorageProvider Members
public bool ReadOnly
{
get { return true; }
}
#endregion
#region IProvider Members
public void Init(IHost host, string config)
{
this.host = host;
this.connectionString = config;
}
public void Shutdown()
{
}
public ComponentInformation Information
{
get { return info; }
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -