Initial import
This commit is contained in:
parent
0c865416ca
commit
04804b89a9
279 changed files with 12945 additions and 0 deletions
27
NpgsqlMRPProviders/AssemblyInfo.cs
Normal file
27
NpgsqlMRPProviders/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("NpgsqlMRPProviders")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("paul")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
||||
68
NpgsqlMRPProviders/NpgsqlMRPProviders.csproj
Normal file
68
NpgsqlMRPProviders/NpgsqlMRPProviders.csproj
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{BBA7175D-7F92-4278-96FC-84C495A2B5A6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Npgsql.Web</RootNamespace>
|
||||
<AssemblyName>NpgsqlMRPProviders</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Compile Include="NpgsqlMembershipProvider.cs" />
|
||||
<Compile Include="NpgsqlRoleProvider.cs" />
|
||||
<Compile Include="NpgsqlProfileProvider.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="Npgsql" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Web.ApplicationServices" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.Linq" />
|
||||
<Reference Include="System.Core" />
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<MonoDevelop>
|
||||
<Properties>
|
||||
<Policies>
|
||||
<DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedFlat" ResourceNamePolicy="FileFormatDefault" />
|
||||
</Policies>
|
||||
</Properties>
|
||||
</MonoDevelop>
|
||||
</ProjectExtensions>
|
||||
<ItemGroup>
|
||||
<Folder Include="Sql\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Sql\UsersTable.sql" />
|
||||
<None Include="Sql\ProfileData.sql" />
|
||||
<None Include="Sql\RolesTable.sql" />
|
||||
<None Include="Sql\UserRoleTable.sql" />
|
||||
<None Include="Sql\StockSymbols.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
1211
NpgsqlMRPProviders/NpgsqlMembershipProvider.cs
Normal file
1211
NpgsqlMRPProviders/NpgsqlMembershipProvider.cs
Normal file
File diff suppressed because it is too large
Load diff
237
NpgsqlMRPProviders/NpgsqlProfileProvider.cs
Normal file
237
NpgsqlMRPProviders/NpgsqlProfileProvider.cs
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.Web.Profile;
|
||||
using Npgsql;
|
||||
|
||||
namespace Npgsql.Web
|
||||
{
|
||||
public class NpgsqlProfileProvider: ProfileProvider
|
||||
{
|
||||
private string connectionString;
|
||||
private string applicationName;
|
||||
|
||||
public NpgsqlProfileProvider ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Initialize (string iname, System.Collections.Specialized.NameValueCollection config)
|
||||
{
|
||||
// get the
|
||||
// - application name
|
||||
// - connection string name
|
||||
// - the connection string from its name
|
||||
string cnxName = config ["connectionStringName"];
|
||||
connectionString = ConfigurationManager.ConnectionStrings [cnxName].ConnectionString;
|
||||
config.Remove ("connectionStringName");
|
||||
applicationName = config ["applicationName"];
|
||||
config.Remove ("applicationName");
|
||||
base.Initialize (iname, config);
|
||||
}
|
||||
|
||||
#region implemented abstract members of System.Web.Profile.ProfileProvider
|
||||
|
||||
public override int DeleteInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public override int DeleteProfiles (string[] usernames)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public override int DeleteProfiles (ProfileInfoCollection profiles)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public override ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public override ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
if (pageIndex < 0)
|
||||
throw new ArgumentException ("pageIndex");
|
||||
if (pageSize < 1)
|
||||
throw new ArgumentException ("pageSize");
|
||||
|
||||
long lowerBound = (long)pageIndex * pageSize;
|
||||
long upperBound = lowerBound + pageSize - 1;
|
||||
if (upperBound > Int32.MaxValue)
|
||||
throw new ArgumentException ("lowerBound + pageSize*pageIndex -1 > Int32.MaxValue");
|
||||
ProfileInfoCollection c = new ProfileInfoCollection ();
|
||||
totalRecords = 0;
|
||||
|
||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
cmd.CommandText = "select username, uniqueid, lastactivitydate, lastupdateddate, isanonymous from profiles where username like @username and applicationname = @appname";
|
||||
cmd.Parameters.Add ("@username", usernameToMatch);
|
||||
cmd.Parameters.Add ("@appname", applicationName);
|
||||
cnx.Open ();
|
||||
using (NpgsqlDataReader r = cmd.ExecuteReader ()) {
|
||||
if (r.HasRows) {
|
||||
while (r.Read ()) {
|
||||
if (totalRecords >= lowerBound && totalRecords <= upperBound) {
|
||||
|
||||
object o = r.GetValue (r.GetOrdinal ("isanonymous"));
|
||||
bool isanon = o is DBNull ? true : (bool) o;
|
||||
o = r.GetValue (r.GetOrdinal ("lastactivitydate"));
|
||||
DateTime lact = o is DBNull ? new DateTime() : (DateTime) o;
|
||||
o = r.GetValue (r.GetOrdinal ("lastupdateddate"));
|
||||
DateTime lupd = o is DBNull ? new DateTime() : (DateTime) o;
|
||||
ProfileInfo pi =
|
||||
new ProfileInfo (
|
||||
r.GetString (r.GetOrdinal ("username")),
|
||||
isanon,
|
||||
lact,
|
||||
lupd,
|
||||
0);
|
||||
c.Add (pi);
|
||||
totalRecords++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public override ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public override ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public override int GetNumberOfInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region implemented abstract members of System.Configuration.SettingsProvider
|
||||
|
||||
public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context, SettingsPropertyCollection collection)
|
||||
{
|
||||
SettingsPropertyValueCollection c = new SettingsPropertyValueCollection ();
|
||||
if (collection == null || collection.Count < 1 || context == null)
|
||||
return c;
|
||||
string username = (string)context ["UserName"];
|
||||
if (String.IsNullOrEmpty (username))
|
||||
return c;
|
||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
cmd.CommandText = "SELECT * from profiledata,profiles where " +
|
||||
"profiledata.uniqueid = profiles.uniqueid " +
|
||||
"and profiles.username = @username " +
|
||||
"and profiles.applicationname = @appname";
|
||||
cmd.Parameters.Add ("@username", username);
|
||||
cmd.Parameters.Add ("@appname", applicationName);
|
||||
cnx.Open ();
|
||||
using (NpgsqlDataReader r = cmd.ExecuteReader (
|
||||
System.Data.CommandBehavior.CloseConnection | System.Data.CommandBehavior.SingleRow)) {
|
||||
if (r.Read ()) {
|
||||
foreach (SettingsProperty p in collection) {
|
||||
SettingsPropertyValue v = new SettingsPropertyValue (p);
|
||||
int o = r.GetOrdinal (p.Name.ToLower ());
|
||||
v.PropertyValue = r.GetValue (o);
|
||||
c.Add (v);
|
||||
}
|
||||
} else {
|
||||
foreach (SettingsProperty p in collection) {
|
||||
SettingsPropertyValue v = new SettingsPropertyValue (p);
|
||||
v.PropertyValue = null;
|
||||
c.Add (v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
public override void SetPropertyValues (SettingsContext context, SettingsPropertyValueCollection collection)
|
||||
{
|
||||
// get the unique id of the profile
|
||||
if (collection == null)
|
||||
return;
|
||||
long puid = 0;
|
||||
string username = (string)context ["UserName"];
|
||||
|
||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
||||
cnx.Open ();
|
||||
using (NpgsqlCommand cmdpi = cnx.CreateCommand ()) {
|
||||
cmdpi.CommandText = "select count(uniqueid) " +
|
||||
"from profiles where username = @username " +
|
||||
"and applicationname = @appname";
|
||||
cmdpi.Parameters.Add ("@username", username);
|
||||
cmdpi.Parameters.Add ("@appname", applicationName);
|
||||
|
||||
long c = (long)cmdpi.ExecuteScalar ();
|
||||
if (c == 0) {
|
||||
cmdpi.CommandText = "insert into profiles (username,applicationname) " +
|
||||
"values ( @username, @appname ) " +
|
||||
"returning uniqueid";
|
||||
puid = (long)cmdpi.ExecuteScalar ();
|
||||
// TODO spec: profiledata insertion <=> profile insertion
|
||||
// => BAD DESIGN
|
||||
//
|
||||
using (NpgsqlCommand cmdpdins = cnx.CreateCommand ()) {
|
||||
cmdpdins.CommandText = "insert into profiledata (uniqueid) values (@puid)";
|
||||
cmdpdins.Parameters.Add ("@puid", puid);
|
||||
cmdpdins.ExecuteNonQuery ();
|
||||
}
|
||||
} else {
|
||||
cmdpi.CommandText = "select uniqueid from profiles where username = @username " +
|
||||
"and applicationname = @appname";
|
||||
puid = (long)cmdpi.ExecuteScalar ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (SettingsPropertyValue s in collection) {
|
||||
if (s.UsingDefaultValue) {
|
||||
//TODO Drop the property in the profile
|
||||
} else {
|
||||
// update the property value
|
||||
// TODO update to null values (included to avoid Not Implemented columns in profiledata
|
||||
if (s.PropertyValue != null) {
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||
cmd.CommandText = string.Format (
|
||||
"update profiledata " +
|
||||
"set {0} = @val " +
|
||||
"where uniqueid = @puid ",
|
||||
s.Name
|
||||
);
|
||||
cmd.Parameters.Add ("@puid", puid);
|
||||
cmd.Parameters.Add ("@val", s.PropertyValue);
|
||||
cmd.ExecuteNonQuery ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ApplicationName {
|
||||
get {
|
||||
return applicationName;
|
||||
}
|
||||
set {
|
||||
applicationName = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
364
NpgsqlMRPProviders/NpgsqlRoleProvider.cs
Normal file
364
NpgsqlMRPProviders/NpgsqlRoleProvider.cs
Normal file
|
|
@ -0,0 +1,364 @@
|
|||
using System;
|
||||
using System.Web.Security;
|
||||
using System.Configuration.Provider;
|
||||
using System.Configuration;
|
||||
using Npgsql;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/*
|
||||
*
|
||||
CREATE TABLE roles
|
||||
(
|
||||
rolename character varying(255) NOT NULL,
|
||||
applicationname character varying(255) NOT NULL,
|
||||
comment character varying(255) NOT NULL,
|
||||
CONSTRAINT roles_pkey PRIMARY KEY (rolename , applicationname )
|
||||
)
|
||||
WITH (
|
||||
OIDS=FALSE
|
||||
);
|
||||
|
||||
CREATE TABLE usersroles
|
||||
(
|
||||
applicationname character varying(255) NOT NULL,
|
||||
rolename character varying(255) NOT NULL,
|
||||
username character varying(255) NOT NULL,
|
||||
CONSTRAINT attrroles_pkey PRIMARY KEY (applicationname , rolename , username ),
|
||||
CONSTRAINT usersroles_fk_role FOREIGN KEY (applicationname, rolename)
|
||||
REFERENCES roles (applicationname, rolename) MATCH SIMPLE
|
||||
ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
CONSTRAINT usersroles_fk_user FOREIGN KEY (applicationname, username)
|
||||
REFERENCES users (applicationname, username) MATCH SIMPLE
|
||||
ON UPDATE CASCADE ON DELETE CASCADE
|
||||
)
|
||||
WITH (
|
||||
OIDS=FALSE
|
||||
);
|
||||
|
||||
*/
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace Npgsql.Web
|
||||
{
|
||||
public class NpgsqlRoleProvider: RoleProvider
|
||||
{
|
||||
protected string name = "NpgsqlRoleProvider";
|
||||
protected string connectionStringName = "pgProvider";
|
||||
protected string applicationName = "/";
|
||||
protected string connectionString = string.Empty;
|
||||
|
||||
public override void Initialize (string iname, System.Collections.Specialized.NameValueCollection config)
|
||||
{
|
||||
try {
|
||||
|
||||
name = iname ?? config ["name"];
|
||||
|
||||
connectionStringName = config ["connectionStringName"] ?? connectionStringName;
|
||||
|
||||
applicationName = config ["applicationName"] ?? applicationName;
|
||||
|
||||
if (applicationName.Length > 250)
|
||||
throw new ProviderException ("The maximum length for an application name is 250 characters.");
|
||||
|
||||
var cs = ConfigurationManager.ConnectionStrings [connectionStringName];
|
||||
if (cs == null || string.IsNullOrEmpty (cs.ConnectionString)) {
|
||||
throw new ProviderException (
|
||||
string.Format ("The role provider connection string, '{0}', is not defined.", connectionStringName));
|
||||
}
|
||||
|
||||
connectionString = ConfigurationManager.ConnectionStrings [connectionStringName].ConnectionString;
|
||||
if (string.IsNullOrEmpty (connectionString))
|
||||
throw new ConfigurationErrorsException (
|
||||
string.Format (
|
||||
"The connection string for the given name ({0})" +
|
||||
"must be specified in the <connectionStrings>" +
|
||||
"configuration bloc. Aborting.", connectionStringName)
|
||||
);
|
||||
|
||||
} catch (Exception ex) {
|
||||
var message = "Error initializing the role configuration settings";
|
||||
throw new ProviderException (message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddUsersToRoles (string[] usernames, string[] roleNames)
|
||||
{
|
||||
if (usernames.Any (x => x == null) || roleNames.Any (x => x == null)) {
|
||||
throw new ArgumentNullException ();
|
||||
}
|
||||
if (usernames.Any (x => x.Trim () == string.Empty) || (roleNames.Any (x => x.Trim () == string.Empty))) {
|
||||
throw new ArgumentException ("One or more of the supplied usernames or role names are empty.");
|
||||
}
|
||||
|
||||
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "insert into usersroles (applicationname, username, rolename) values (@appname,@user,@role)";
|
||||
comm.Parameters.Add ("appname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
NpgsqlParameter pu = comm.Parameters.Add ("user", NpgsqlTypes.NpgsqlDbType.Varchar, 250);
|
||||
NpgsqlParameter pr = comm.Parameters.Add ("role", NpgsqlTypes.NpgsqlDbType.Varchar, 250);
|
||||
foreach (string u in usernames) {
|
||||
pu.Value = u;
|
||||
foreach (string r in roleNames) {
|
||||
pr.Value = r;
|
||||
comm.ExecuteNonQuery ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override string ApplicationName {
|
||||
get {
|
||||
return applicationName;
|
||||
}
|
||||
set {
|
||||
applicationName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void CreateRole (string roleName)
|
||||
{
|
||||
if (roleName == null)
|
||||
throw new ArgumentNullException ();
|
||||
if (roleName.Trim () == string.Empty)
|
||||
throw new ArgumentException ("A role name cannot be empty.");
|
||||
if (roleName.Contains (","))
|
||||
throw new ArgumentException ("A role name cannot contain commas. Blame Microsoft for that rule!");
|
||||
if (roleName.Length > 250)
|
||||
throw new ArgumentException ("The maximum length for a Role name is 250 characters.");
|
||||
|
||||
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "insert into roles (rolename, applicationname, comment) values (@rolename, @appname, @comment)";
|
||||
comm.Parameters.Add ("@rolename", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = roleName;
|
||||
comm.Parameters.Add ("@appname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
comm.Parameters.Add ("@comment", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = roleName;
|
||||
comm.ExecuteNonQuery ();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override bool DeleteRole (string roleName, bool throwOnPopulatedRole)
|
||||
{
|
||||
if (roleName == null)
|
||||
throw new ArgumentNullException ();
|
||||
if (roleName.Trim () == string.Empty)
|
||||
throw new ArgumentException ("The specified role name cannot be empty.");
|
||||
if (throwOnPopulatedRole)
|
||||
if (FindUsersInRole (roleName, "").Count () > 0)
|
||||
throw new ProviderException (
|
||||
string.Format ("The role {0} is populated, we cannot delete it.", roleName));
|
||||
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "delete from roles where rolename = @rolename and applicationname = @appname";
|
||||
comm.Parameters.Add ("@rolename", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = roleName;
|
||||
comm.Parameters.Add ("@appname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
comm.Parameters.Add ("@comment", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = roleName;
|
||||
comm.ExecuteNonQuery ();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string[] FindUsersInRole (string roleName, string usernameToMatch)
|
||||
{
|
||||
return GetUsersInRole (roleName, usernameToMatch);
|
||||
}
|
||||
|
||||
protected string[] GetUsersInRole (string rolename, string usernameToMatch)
|
||||
{
|
||||
if (rolename == null)
|
||||
throw new ArgumentNullException ();
|
||||
if (rolename == string.Empty)
|
||||
throw new ProviderException ("Cannot look for blank role names.");
|
||||
usernameToMatch = usernameToMatch ?? string.Empty;
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "select username from usersroles where applicationname = @appname " +
|
||||
"and rolename = @rolename and username like @username";
|
||||
comm.Parameters.Add ("@rolename", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = rolename;
|
||||
comm.Parameters.Add ("@appname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
comm.Parameters.Add ("@username", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = usernameToMatch;
|
||||
using (var reader = comm.ExecuteReader()) {
|
||||
var r = new List<string> ();
|
||||
var usernameColumn = reader.GetOrdinal ("username");
|
||||
while (reader.Read()) {
|
||||
r.Add (reader.GetString (usernameColumn));
|
||||
}
|
||||
return r.ToArray ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] GetAllRoles ()
|
||||
{
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "select rolename from roles where applicationname = @appname";
|
||||
comm.Parameters.Add ("@appname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
using (var reader = comm.ExecuteReader()) {
|
||||
var r = new List<string> ();
|
||||
var rolenameColumn = reader.GetOrdinal ("rolename");
|
||||
while (reader.Read()) {
|
||||
r.Add (reader.GetString (rolenameColumn));
|
||||
}
|
||||
return r.ToArray ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] GetRolesForUser (string username)
|
||||
{
|
||||
if (username == null)
|
||||
throw new ArgumentNullException ();
|
||||
if (username.Trim () == string.Empty)
|
||||
throw new ArgumentException ("The specified username cannot be blank.");
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "select rolename from usersroles where applicationname = @appname and username = @username";
|
||||
comm.Parameters.Add ("@username", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = username;
|
||||
comm.Parameters.Add ("@appname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
using (var reader = comm.ExecuteReader()) {
|
||||
var r = new List<string> ();
|
||||
var rolenameColumn = reader.GetOrdinal ("rolename");
|
||||
while (reader.Read()) {
|
||||
r.Add (reader.GetString (rolenameColumn));
|
||||
}
|
||||
return r.ToArray ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] GetUsersInRole (string roleName)
|
||||
{
|
||||
if (string.IsNullOrEmpty (roleName))
|
||||
throw new ArgumentException ("The specified role name cannot be blank or null");
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
//
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "select username from usersroles where applicationname = @appname " +
|
||||
"and rolename = @rolename";
|
||||
comm.Parameters.Add ("@rolename", NpgsqlTypes.NpgsqlDbType.Varchar, 255).Value = roleName;
|
||||
comm.Parameters.Add ("@appname", NpgsqlTypes.NpgsqlDbType.Varchar, 255).Value = applicationName;
|
||||
using (var reader = comm.ExecuteReader()) {
|
||||
var r = new List<string> ();
|
||||
var usernameColumn = reader.GetOrdinal ("username");
|
||||
while (reader.Read()) {
|
||||
r.Add (reader.GetString (usernameColumn));
|
||||
}
|
||||
return r.ToArray ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsUserInRole (string username, string roleName)
|
||||
{
|
||||
if (username == null || roleName == null)
|
||||
throw new ArgumentNullException ();
|
||||
if (username.Trim () == string.Empty)
|
||||
throw new ArgumentException ("The specified username cannot be blank.");
|
||||
if (roleName.Trim () == string.Empty)
|
||||
throw new ArgumentException ("The specified role name cannot be blank.");
|
||||
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
//
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "select count(*)>0 from usersroles where applicationname = @appname " +
|
||||
"and username = @username and rolename = @rolename";
|
||||
comm.Parameters.Add ("@username", username);
|
||||
comm.Parameters.Add ("@rolename", roleName);
|
||||
comm.Parameters.Add ("@appname", applicationName);
|
||||
var retval = (bool)comm.ExecuteScalar ();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void RemoveUsersFromRoles (string[] usernames, string[] roleNames)
|
||||
{
|
||||
if (usernames.Any (x => x == null) || roleNames.Any (x => x == null)) {
|
||||
throw new ArgumentNullException ();
|
||||
}
|
||||
if (usernames.Any (x => x.Trim () == string.Empty) || (roleNames.Any (x => x.Trim () == string.Empty))) {
|
||||
throw new ArgumentException ("One or more of the supplied usernames or role names are empty.");
|
||||
}
|
||||
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = conn.CreateCommand()) {
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "delete from usersroles where applicationname = @appname and " +
|
||||
"username = @username and rolename = @rolename";
|
||||
NpgsqlParameter pu = comm.Parameters.Add ("@username", NpgsqlTypes.NpgsqlDbType.Varchar, 250);
|
||||
NpgsqlParameter pr = comm.Parameters.Add ("@rolename", NpgsqlTypes.NpgsqlDbType.Varchar, 250);
|
||||
comm.Parameters.Add ("@appname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
foreach (string rolename in roleNames) {
|
||||
pr.Value = rolename;
|
||||
foreach (string username in usernames) {
|
||||
pu.Value = username;
|
||||
comm.ExecuteNonQuery ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override bool RoleExists (string roleName)
|
||||
{
|
||||
using (var conn = new NpgsqlConnection(connectionString)) {
|
||||
conn.Open ();
|
||||
using (var comm = new NpgsqlCommand("role_exists", conn)) {
|
||||
comm.CommandType = System.Data.CommandType.Text;
|
||||
comm.CommandText = "select Count(*)>0 from roles where applicationname = @applicationname and rolename = @rolename";
|
||||
comm.Parameters.Add ("@rolename", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = roleName;
|
||||
comm.Parameters.Add ("@applicationname", NpgsqlTypes.NpgsqlDbType.Varchar, 250).Value = applicationName;
|
||||
var retval = (bool)comm.ExecuteScalar ();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Description {
|
||||
get {
|
||||
return "PostgreSQL ASP.Net Role Provider class";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
NpgsqlMRPProviders/Sql/ProfileData.sql
Normal file
28
NpgsqlMRPProviders/Sql/ProfileData.sql
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
-- Table: profiledata
|
||||
|
||||
-- DROP TABLE profiledata;
|
||||
|
||||
CREATE TABLE profiledata
|
||||
(
|
||||
uniqueid integer,
|
||||
zipcode character varying(10),
|
||||
cityandstate character varying(255),
|
||||
avatar bytea,
|
||||
CONSTRAINT fkprofiles2 FOREIGN KEY (uniqueid)
|
||||
REFERENCES profiles (uniqueid) MATCH SIMPLE
|
||||
ON UPDATE CASCADE ON DELETE CASCADE
|
||||
)
|
||||
WITH (
|
||||
OIDS=FALSE
|
||||
);
|
||||
|
||||
-- Index: fki_fkprofiles2
|
||||
|
||||
-- DROP INDEX fki_fkprofiles2;
|
||||
|
||||
CREATE INDEX fki_fkprofiles2
|
||||
ON profiledata
|
||||
USING btree
|
||||
(uniqueid );
|
||||
|
||||
|
||||
18
NpgsqlMRPProviders/Sql/RolesTable.sql
Normal file
18
NpgsqlMRPProviders/Sql/RolesTable.sql
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
-- Table: roles
|
||||
|
||||
-- DROP TABLE roles;
|
||||
|
||||
CREATE TABLE roles
|
||||
(
|
||||
rolename character varying(255) NOT NULL,
|
||||
applicationname character varying(255) NOT NULL,
|
||||
comment character varying(255) NOT NULL,
|
||||
CONSTRAINT roles_pkey PRIMARY KEY (rolename , applicationname )
|
||||
)
|
||||
WITH (
|
||||
OIDS=FALSE
|
||||
);
|
||||
|
||||
COMMENT ON TABLE roles
|
||||
IS 'Web application roles';
|
||||
|
||||
16
NpgsqlMRPProviders/Sql/StockSymbols.sql
Normal file
16
NpgsqlMRPProviders/Sql/StockSymbols.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
-- Table: stocksymbols
|
||||
|
||||
-- DROP TABLE stocksymbols;
|
||||
|
||||
CREATE TABLE stocksymbols
|
||||
(
|
||||
uniqueid integer,
|
||||
stocksymbol character varying(10),
|
||||
CONSTRAINT fkprofiles1 FOREIGN KEY (uniqueid)
|
||||
REFERENCES profiles (uniqueid) MATCH SIMPLE
|
||||
ON UPDATE NO ACTION ON DELETE NO ACTION
|
||||
)
|
||||
WITH (
|
||||
OIDS=FALSE
|
||||
);
|
||||
21
NpgsqlMRPProviders/Sql/UserRoleTable.sql
Normal file
21
NpgsqlMRPProviders/Sql/UserRoleTable.sql
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
-- Table: usersroles
|
||||
|
||||
-- DROP TABLE usersroles;
|
||||
|
||||
CREATE TABLE usersroles
|
||||
(
|
||||
applicationname character varying(255) NOT NULL,
|
||||
rolename character varying(255) NOT NULL,
|
||||
username character varying(255) NOT NULL,
|
||||
CONSTRAINT attrroles_pkey PRIMARY KEY (applicationname , rolename , username ),
|
||||
CONSTRAINT usersroles_fk_role FOREIGN KEY (applicationname, rolename)
|
||||
REFERENCES roles (applicationname, rolename) MATCH SIMPLE
|
||||
ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
CONSTRAINT usersroles_fk_user FOREIGN KEY (applicationname, username)
|
||||
REFERENCES users (applicationname, username) MATCH SIMPLE
|
||||
ON UPDATE CASCADE ON DELETE CASCADE
|
||||
)
|
||||
WITH (
|
||||
OIDS=FALSE
|
||||
);
|
||||
19
NpgsqlMRPProviders/Sql/UsersTable.sql
Normal file
19
NpgsqlMRPProviders/Sql/UsersTable.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
-- Table: profiles
|
||||
|
||||
-- DROP TABLE profiles;
|
||||
|
||||
CREATE TABLE profiles
|
||||
(
|
||||
uniqueid bigserial NOT NULL,
|
||||
username character varying(255) NOT NULL,
|
||||
applicationname character varying(255) NOT NULL,
|
||||
isanonymous boolean,
|
||||
lastactivitydate timestamp with time zone,
|
||||
lastupdateddate timestamp with time zone,
|
||||
CONSTRAINT profiles_pkey PRIMARY KEY (uniqueid ),
|
||||
CONSTRAINT pkprofiles UNIQUE (username , applicationname )
|
||||
)
|
||||
WITH (
|
||||
OIDS=FALSE
|
||||
);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue