活动页面添加参赛作品瀑布流
[PumpkinHouse.git] / PumpkinHouseWeb / Account / RoleProvider.cs
blobce468ca4deac9a597623554026c23eb4e6ef77c6
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.Security;
6 using PumpkinHouseDatabase;
8 namespace PumpkinHouse
10 public class RoleProvider : SqlRoleProvider
12 public override bool IsUserInRole(string username, string roleName)
14 if (roleName == "admin")
16 using (DataUtils utils = new DataUtils(false))
18 DB_User user = utils.FindUserByNameOrEmail(username);
19 if (user == null)
21 return false;
23 return user.Is_Admin == 1;
26 if (roleName == "locked")
28 using (DataUtils utils = new DataUtils(false))
30 DB_User user = utils.FindUserByNameOrEmail(username);
31 if (user == null)
33 return false;
35 if (user.Is_Locked == 1)
37 HttpContext.Current.Session["username"] = user.Username;
38 HttpContext.Current.Session["lockedReason"] = user.Locked_Reason;
39 return true;
41 return false;
44 return true;
47 public override string[] GetRolesForUser(string username)
49 using (DataUtils utils = new DataUtils(false))
51 DB_User user = utils.FindUserByNameOrEmail(username);
52 if (user.Is_Locked == 1)
54 return new string[] { "locked" };
56 if (user.Is_Admin == 1)
58 return new string[] { "admin" };
60 return new string[] { };
64 public override string[] GetAllRoles()
66 return new string[] { "admin", "locked" };