本文整理汇总了C#中IIdentity.GetUserId方法的典型用法代码示例。如果您正苦于以下问题:C# IIdentity.GetUserId方法的具体用法?C# IIdentity.GetUserId怎么用?C# IIdentity.GetUserId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IIdentity
的用法示例。
在下文中一共展示了IIdentity.GetUserId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetQueriesForUser
public IList<Query> GetQueriesForUser(IIdentity identity)
{
var userId = identity.GetUserId();
var orgId = identity.GetOrganizationId();
return Queries.Where(q =>
(q.User == null || q.User == userId) &&
(q.Org == null || q.Org == orgId)
).OrderBy(q => q.Description).ToList();
}
示例2: ProjectController
public ProjectController(IProjectRepository repository,
ITimeSheetUnitOfWork uow,
IPersonRepository personRepository,
IIdentity claimsIdentity)
{
CurrentUserId = claimsIdentity.GetUserId();
this.repository = repository;
this.uow = uow;
this.personRepository = personRepository;
}
示例3: IsInRole
public bool IsInRole(string role, IIdentity identity)
{
if (identity != null && identity.IsAuthenticated)
{
var userID = identity.GetUserId();
var userrole = _context.Roles.SingleOrDefault(x => x.Users.Any(y => y.UserId == userID) && x.Name == role);
if (userrole != null)
{
return true;
}
}
return false;
}
示例4: IsAuthorized
public bool IsAuthorized(IIdentity identity, IAuthorizableItem item)
{
var userManager = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
var identityUser = userManager.FindById(identity.GetUserId());
if (identityUser == null)
return false;
var dbUser = FileSyncDal.Instance.GetDbUser(identityUser.Id);
if (dbUser == null)
return false;
if (userManager.IsInRole(dbUser.Id, "Admin"))
return true;
if (CheckIfItemAllowed(dbUser, item))
return true;
return CheckIfItemParentFoldersAllowed(dbUser, item.ParentFolder);
}
示例5: send_notifications
//.........这里部分代码省略.........
select us_email, us_id, us_username, us_admin, og.*
from bug_subscriptions
inner join users on bs_user = us_id
inner join orgs og on us_org = og_id
inner join bugs on bg_id = bs_bug
left outer join project_user_xref on pu_user = us_id and pu_project = bg_project
where us_email is not null
and us_enable_notifications = 1
-- @status_change
and us_active = 1
and us_email <> ''
and ( (@cl <= us_reported_notifications and bg_reported_user = bs_user)
or (@cl <= us_assigned_notifications and bg_assigned_to_user = bs_user)
or (@cl <= us_assigned_notifications and @pau = bs_user)
or (@cl <= us_subscribed_notifications))
and
case
when
us_org <> bg_org
and og_other_orgs_permission_level < 2
and og_other_orgs_permission_level < isnull(pu_permission_level,@dpl)
then og_other_orgs_permission_level
else
isnull(pu_permission_level,@dpl)
end <> 0
and bs_bug = @id
and (us_id <> @us or isnull(us_send_notifications_to_self,0) = 1)");
}
sql = sql.AddParameterWithValue("@cl", changeLevel);
sql = sql.AddParameterWithValue("@pau", prev_assigned_to_user);
sql = sql.AddParameterWithValue("@id", bugid);
sql = sql.AddParameterWithValue("@dpl", Convert.ToInt32(btnet.Util.get_setting("DefaultPermissionLevel", "2")));
sql = sql.AddParameterWithValue("@us", identity.GetUserId());
DataSet ds_subscribers = btnet.DbUtil.get_dataset(sql);
if (ds_subscribers.Tables[0].Rows.Count > 0)
{
bool added_to_queue = false;
// Get bug html
DataRow bug_dr = btnet.Bug.get_bug_datarow(bugid, identity);
string from = btnet.Util.get_setting("NotificationEmailFrom", "");
// Format the subject line
string subject = btnet.Util.get_setting("NotificationSubjectFormat", "$THING$:$BUGID$ was $ACTION$ - $SHORTDESC$ $TRACKINGID$");
subject = subject.Replace("$THING$", btnet.Util.capitalize_first_letter(btnet.Util.get_setting("SingularBugLabel", "bug")));
string action = "";
if (insert_or_update == INSERT)
{
action = "added";
}
else
{
action = "updated";
}
subject = subject.Replace("$ACTION$", action);
subject = subject.Replace("$BUGID$", Convert.ToString(bugid));
示例6: insert_bug
///////////////////////////////////////////////////////////////////////
public static NewIds insert_bug(string short_desc, IIdentity identity, string tags, int projectid, int orgid, int categoryid, int priorityid, int statusid, int assigned_to_userid, int udfid, string comment_formated, string comment_search, string @from, string cc, string content_type, bool internal_only, SortedDictionary<string, string> hash_custom_cols, bool send_notifications)
{
if (short_desc.Trim() == "")
{
short_desc = "[No Description]";
}
if (assigned_to_userid == 0)
{
assigned_to_userid = btnet.Util.get_default_user(projectid);
}
var sql = new SQLString(@"insert into bugs
(bg_short_desc,
bg_tags,
bg_reported_user,
bg_last_updated_user,
bg_reported_date,
bg_last_updated_date,
bg_project,
bg_org,
bg_category,
bg_priority,
bg_status,
bg_assigned_to_user,
bg_user_defined_attribute)
values (@short_desc, @tags, @reported_user, @reported_user, getdate(), getdate(),
@project, @org,
@category, @priority, @status, @assigned_user, @udf)");
sql = sql.AddParameterWithValue("@short_desc", short_desc);
sql = sql.AddParameterWithValue("@tags", tags);
sql = sql.AddParameterWithValue("@reported_user", Convert.ToString(identity.GetUserId()));
sql = sql.AddParameterWithValue("@project", Convert.ToString(projectid));
sql = sql.AddParameterWithValue("@org", Convert.ToString(orgid));
sql = sql.AddParameterWithValue("@category", Convert.ToString(categoryid));
sql = sql.AddParameterWithValue("@priority", Convert.ToString(priorityid));
sql = sql.AddParameterWithValue("@status", Convert.ToString(statusid));
sql = sql.AddParameterWithValue("@assigned_user", Convert.ToString(assigned_to_userid));
sql = sql.AddParameterWithValue("@udf", Convert.ToString(udfid));
//TODO: Add custom columns
sql.Append("\nselect scope_identity()");
int bugid = Convert.ToInt32(btnet.DbUtil.execute_scalar(sql));
int postid = btnet.Bug.insert_comment(
bugid,
identity.GetUserId(),
comment_formated,
comment_search,
from,
cc,
content_type,
internal_only);
btnet.Bug.auto_subscribe(bugid);
if (send_notifications)
{
btnet.Bug.send_notifications(btnet.Bug.INSERT, bugid, identity);
}
return new NewIds(bugid, postid);
}
示例7: get_bug_permission_level
///////////////////////////////////////////////////////////////////////
public static int get_bug_permission_level(int bugid, IIdentity identity)
{
/*
public const int PERMISSION_NONE = 0;
public const int PERMISSION_READONLY = 1;
public const int PERMISSION_REPORTER = 3;
public const int PERMISSION_ALL = 2;
*/
// fetch the revised permission level
var sql = new SQLString(@"
declare @bg_org int
select isnull(pu_permission_level,@dpl),
bg_org
from bugs
left outer join project_user_xref
on pu_project = bg_project
and pu_user = @us
where bg_id = @bg");
;
sql = sql.AddParameterWithValue("@dpl", Util.get_setting("DefaultPermissionLevel", "2"));
sql = sql.AddParameterWithValue("@bg", Convert.ToString(bugid));
sql = sql.AddParameterWithValue("@us", Convert.ToString(identity.GetUserId()));
DataRow dr = btnet.DbUtil.get_datarow(sql);
if (dr == null)
{
return PermissionLevel.None;
}
int pl = (int)dr[0];
int bg_org = (int)dr[1];
// maybe reduce permissions
var organizationId = identity.GetOrganizationId();
if (bg_org != organizationId)
{
var otherOrgsPermissionLevel = identity.GetOtherOrgsPermissionLevels();
if (otherOrgsPermissionLevel == PermissionLevel.None
|| otherOrgsPermissionLevel == PermissionLevel.ReadOnly)
{
if (otherOrgsPermissionLevel < pl)
{
pl = otherOrgsPermissionLevel;
}
}
}
return pl;
}
示例8: get_bug_datarow
//.........这里部分代码省略.........
}
sql.Append(@"
select bg_id [id],
bg_short_desc [short_desc],
isnull(bg_tags,'') [bg_tags],
isnull(ru.us_username,'[deleted user]') [reporter],
isnull(ru.us_email,'') [reporter_email],
case rtrim(ru.us_firstname)
when null then isnull(ru.us_lastname, '')
when '' then isnull(ru.us_lastname, '')
else isnull(ru.us_lastname + ', ' + ru.us_firstname,'')
end [reporter_fullname],
bg_reported_date [reported_date],
datediff(s,bg_reported_date,getdate()) [seconds_ago],
isnull(lu.us_username,'') [last_updated_user],
case rtrim(lu.us_firstname)
when null then isnull(lu.us_lastname, '')
when '' then isnull(lu.us_lastname, '')
else isnull(lu.us_lastname + ', ' + lu.us_firstname,'')
end [last_updated_fullname],
bg_last_updated_date [last_updated_date],
isnull(bg_project,0) [project],
isnull(pj_name,'[no project]') [current_project],
isnull(bg_org,0) [organization],
isnull(bugorg.og_name,'') [og_name],
isnull(bg_category,0) [category],
isnull(ct_name,'') [category_name],
isnull(bg_priority,0) [priority],
isnull(pr_name,'') [priority_name],
isnull(bg_status,0) [status],
isnull(st_name,'') [status_name],
isnull(bg_user_defined_attribute,0) [udf],
isnull(udf_name,'') [udf_name],
isnull(bg_assigned_to_user,0) [assigned_to_user],
isnull(asg.us_username,'[not assigned]') [assigned_to_username],
case rtrim(asg.us_firstname)
when null then isnull(asg.us_lastname, '[not assigned]')
when '' then isnull(asg.us_lastname, '[not assigned]')
else isnull(asg.us_lastname + ', ' + asg.us_firstname,'[not assigned]')
end [assigned_to_fullname],
isnull(bs_user,0) [subscribed],
case
when
@this_org <> bg_org
and userorg.og_other_orgs_permission_level < 2
and userorg.og_other_orgs_permission_level < isnull(pu_permission_level,@dpl)
then userorg.og_other_orgs_permission_level
else
isnull(pu_permission_level,@dpl)
end [pu_permission_level],
isnull(bg_project_custom_dropdown_value1,'') [bg_project_custom_dropdown_value1],
isnull(bg_project_custom_dropdown_value2,'') [bg_project_custom_dropdown_value2],
isnull(bg_project_custom_dropdown_value3,'') [bg_project_custom_dropdown_value3],
@related [relationship_cnt],
@svn_revisions [svn_revision_cnt],
@git_commits [git_commit_cnt],
@hg_revisions [hg_commit_cnt],
@tasks [task_cnt],
getdate() [snapshot_timestamp]
from bugs
inner join users this_user on us_id = @this_usid
inner join orgs userorg on this_user.us_org = userorg.og_id
left outer join user_defined_attribute on bg_user_defined_attribute = udf_id
left outer join projects on bg_project = pj_id
left outer join orgs bugorg on bg_org = bugorg.og_id
left outer join categories on bg_category = ct_id
left outer join priorities on bg_priority = pr_id
left outer join statuses on bg_status = st_id
left outer join users asg on bg_assigned_to_user = asg.us_id
left outer join users ru on bg_reported_user = ru.us_id
left outer join users lu on bg_last_updated_user = lu.us_id
left outer join bug_subscriptions on bs_bug = bg_id and bs_user = @this_usid
left outer join project_user_xref on pj_id = pu_project
and pu_user = @this_usid
where bg_id = @id");
sql = sql.AddParameterWithValue("id", Convert.ToString(bugid));
sql = sql.AddParameterWithValue("this_usid", Convert.ToString(identity.GetUserId()));
sql = sql.AddParameterWithValue("this_org", Convert.ToString(identity.GetOrganizationId()));
sql = sql.AddParameterWithValue("dpl", Util.get_setting("DefaultPermissionLevel", "2"));
return btnet.DbUtil.get_datarow(sql);
}
示例9: insert_post_attachment_impl
///////////////////////////////////////////////////////////////////////
private static int insert_post_attachment_impl(
IIdentity identity,
int bugid,
Stream content,
int content_length,
int copy_bpid,
string file,
string comment,
string content_type,
int parent,
bool hidden_from_external_users,
bool send_notifications)
{
// Note that this method does not perform any security check nor does
// it check that content_length is less than MaxUploadSize.
// These are left up to the caller.
string upload_folder = Util.get_upload_folder();
SQLString sql;
bool store_attachments_in_database = (Util.get_setting("StoreAttachmentsInDatabase", "0") == "1");
string effective_file = file;
int effective_content_length = content_length;
string effective_content_type = content_type;
Stream effective_content = null;
try
{
// Determine the content. We may be instructed to copy an existing
// attachment via copy_bpid, or a Stream may be provided as the content parameter.
if (copy_bpid != -1)
{
BugPostAttachment bpa = get_bug_post_attachment(copy_bpid);
effective_content = bpa.content;
effective_file = bpa.file;
effective_content_length = bpa.content_length;
effective_content_type = bpa.content_type;
}
else
{
effective_content = content;
effective_file = file;
effective_content_length = content_length;
effective_content_type = content_type;
}
// Insert a new post into bug_posts.
sql = new SQLString(@"
declare @now datetime
set @now = getdate()
update bugs
set bg_last_updated_date = @now,
bg_last_updated_user = @us
where bg_id = @bg
insert into bug_posts
(bp_type, bp_bug, bp_file, bp_comment, bp_size, bp_date, bp_user, bp_content_type, bp_parent, bp_hidden_from_external_users)
values ('file', @bg, @fi, @de, @si, @now, @us, @ct, @pa, @internal)
select scope_identity()");
sql = sql.AddParameterWithValue("@bg", Convert.ToString(bugid));
sql = sql.AddParameterWithValue("@fi", effective_file);
sql = sql.AddParameterWithValue("@de", comment);
sql = sql.AddParameterWithValue("@si", Convert.ToString(effective_content_length));
sql = sql.AddParameterWithValue("@us", Convert.ToString(identity.GetUserId()));
// Sometimes, somehow, content type is null. Not sure how.
sql = sql.AddParameterWithValue("@ct",
effective_content_type != null
? effective_content_type.Replace("'", "''")
: string.Empty);
if (parent == -1)
{
sql = sql.AddParameterWithValue("@pa", DBNull.Value);
}
else
{
sql = sql.AddParameterWithValue("@pa", parent);
}
sql = sql.AddParameterWithValue("@internal", btnet.Util.bool_to_string(hidden_from_external_users));
int bp_id = Convert.ToInt32(btnet.DbUtil.execute_scalar(sql));
try
{
// Store attachment in bug_post_attachments table.
if (store_attachments_in_database)
{
byte[] data = new byte[effective_content_length];
int bytes_read = 0;
while (bytes_read < effective_content_length)
//.........这里部分代码省略.........
示例10: GetVerificationCodesAsync
public Task<UserVerification> GetVerificationCodesAsync(IIdentity identity)
{
int userId = Int32.Parse(identity.GetUserId());
return this.UsersManager.GetVerificationCodesAsync(userId);
}
示例11: IsLockedBy
public bool IsLockedBy(IIdentity identity)
{
return IsLocked && LockedById == identity.GetUserId();
}
示例12: get_related_users
//.........这里部分代码省略.........
where pu2.pu_user = @userid
and pu2.pu_permission_level <> 0
)
and pu1.pu_permission_level <> 0
)
if @og_external_user = 1 -- external
and @og_other_orgs_permission_level = 0 -- other orgs
begin
delete from #temp where og_external_user = 1 and us_org <> @userorg
end
");
if (Util.get_setting("LimitUsernameDropdownsInSearch", "0") == "1")
{
sql.Append(limitUsernameDropdownSql);
}
sql.Append(@"
select us_id, us_username, us_email from #temp order by us_username
drop table #temp");
}
else
{
// show users UNLESS they have been explicitly excluded
// from all the projects the viewer is able to view
// the cartesian join in the first select is intentional
sql= new SQLString(@"
/* get related users 2 */
select pj_id, us_id,
case when @fullnames = 1 then
case when len(isnull(us_firstname,'') + ' ' + isnull(us_lastname,'')) > 1
then isnull(us_firstname,'') + ' ' + isnull(us_lastname,'')
else us_username end
else us_username end us_username,
isnull(us_email,'') us_email
into #temp
from projects, users
where pj_id not in
(
select pu_project from project_user_xref
where pu_permission_level = 0 and pu_user = @userid
)
");
if (Util.get_setting("LimitUsernameDropdownsInSearch", "0") == "1")
{
sql.Append(limitUsernameDropdownSql);
}
sql.Append(@"
if @og_external_user = 1 -- external
and @og_other_orgs_permission_level = 0 -- other orgs
begin
select distinct a.us_id, a.us_username, a.us_email
from #temp a
inner join users b on a.us_id = b.us_id
inner join orgs on b.us_org = og_id
where og_external_user = 0 or b.us_org = @userorg
order by a.us_username
end
else
begin
select distinct us_id, us_username, us_email
from #temp
left outer join project_user_xref on pj_id = pu_project
and us_id = pu_user
where isnull(pu_permission_level,2) <> 0
order by us_username
end
drop table #temp");
}
if (force_full_names || Util.get_setting("UseFullNames", "0") == "1")
{
// true condition
sql = sql.AddParameterWithValue("fullnames", 1);
}
else
{
// false condition
sql = sql.AddParameterWithValue("fullnames", 0);
}
sql = sql.AddParameterWithValue("userid",identity.GetUserId());
sql = sql.AddParameterWithValue("userorg",identity.GetOrganizationId());
sql = sql.AddParameterWithValue("og_external_user", identity.GetIsExternalUser() ? 1 : 0);
sql = sql.AddParameterWithValue("og_other_orgs_permission_level",identity.GetOtherOrgsPermissionLevels());
return btnet.DbUtil.get_dataset(sql).Tables[0];
}
示例13: alter_sql_per_project_permissions
///////////////////////////////////////////////////////////////////////
public static SQLString alter_sql_per_project_permissions(SQLString sql, IIdentity identity)
{
int userId = identity.GetUserId();
int organizationId = identity.GetOrganizationId();
string project_permissions_sql;
string dpl = Util.get_setting("DefaultPermissionLevel","2");
if (dpl == "0")
{
project_permissions_sql = @" (bugs.bg_project in (
select pu_project
from project_user_xref
where pu_user = $user
and pu_permission_level > 0)) ";
}
else
{
project_permissions_sql = @" (bugs.bg_project not in (
select pu_project
from project_user_xref
where pu_user = $user
and pu_permission_level = 0)) ";
}
if (identity.GetCanOnlySeeOwnReportedBugs())
{
project_permissions_sql += @"
and bugs.bg_reported_user = $user ";
}
else
{
if (identity.GetOtherOrgsPermissionLevels() == 0)
{
project_permissions_sql += @"
and bugs.bg_org = $user.org ";
}
}
project_permissions_sql
= project_permissions_sql.Replace("$user.org",Convert.ToString(organizationId));
project_permissions_sql
= project_permissions_sql.Replace("$user",Convert.ToString(userId));
// Figure out where to alter sql for project permissions
// I've tried lots of different schemes over the years....
int alter_here_pos = sql.ToString().IndexOf("$ALTER_HERE"); // places - can be multiple - are explicitly marked
if (alter_here_pos != -1)
{
return new SQLString(sql.ToString().Replace("$ALTER_HERE", "/* ALTER_HERE */ " + project_permissions_sql), sql.GetParameters());
}
else
{
string bug_sql;
var rawSQL = sql.ToString();
int where_pos = rawSQL.IndexOf("WhErE"); // first look for a "special" where, case sensitive, in case there are multiple where's to choose from
if (where_pos == -1)
where_pos = rawSQL.ToUpper().IndexOf("WHERE");
int order_pos = rawSQL.IndexOf("/*ENDWHR*/"); // marker for end of the where statement
if (order_pos == -1)
order_pos = rawSQL.ToUpper().LastIndexOf("ORDER BY");
if (order_pos < where_pos)
order_pos = -1; // ignore an order by that occurs in a subquery, for example
if (where_pos != -1 && order_pos != -1)
{
// both WHERE and ORDER BY clauses
bug_sql = rawSQL.Substring(0, where_pos + 5)
+ " /* altered - both */ ( "
+ rawSQL.Substring(where_pos + 5, order_pos - (where_pos + 5))
+ " ) AND ( "
+ project_permissions_sql
+ " ) "
+ rawSQL.Substring(order_pos);
}
else if (order_pos == -1 && where_pos == -1)
{
// Neither
bug_sql = rawSQL + " /* altered - neither */ WHERE " + project_permissions_sql;
}
else if (order_pos == -1)
{
// WHERE, without order
bug_sql = rawSQL.Substring(0, where_pos + 5)
+ " /* altered - just where */ ( "
+ rawSQL.Substring(where_pos + 5)
+ " ) AND ( "
+ project_permissions_sql + " )";
}
else
{
//.........这里部分代码省略.........
示例14: UpdateAsset
private async Task UpdateAsset(TaskCard taskCard, IIdentity identity)
{
var userId = identity.GetUserId<int>();
var isPull = taskCard.IsPull();
var card = taskCard.Card;
var asset = new Asset
{
AssetType = card.AssetType,
AssetPurpose = isPull ? AssetPurpose.Pull : AssetPurpose.Push,
AssetValue = isPull ? card.PullValue : card.PushValue,
UserId = userId,
ModifiedBy = identity.Name,
ModifiedOn = DateTime.Now,
Date = DateTime.Today,
DayOfWeek = (int) DateTime.Today.DayOfWeek
};
await AssetRepository.UpdateAssetAsync(asset);
}
示例15: ExecuteQuery
public BugQueryResult ExecuteQuery(IIdentity identity, int start, int length, string orderBy, string sortDirection, bool idOnly, BugQueryFilter[] filters = null)
{
if (!string.IsNullOrEmpty(orderBy) && !_columnNames.Contains(orderBy))
{
throw new ArgumentException("Invalid order by column specified: {0}", orderBy);
}
bool hasFilters = filters != null && filters.Any();
string columnsToSelect = idOnly ? "id" : "*";
var innerSql = GetInnerSql(identity);
var countSql = string.Format("SELECT COUNT(1) FROM ({0}) t", GetInnerSql(identity));
SQLString sqlString = new SQLString(countSql);
sqlString.Append(";");
if (hasFilters)
{
sqlString.Append(countSql);
ApplyWhereClause(sqlString, filters);
sqlString.Append(";");
}
var bugsSql = string.Format("SELECT t.{0} FROM ({1}) t",columnsToSelect, innerSql);
sqlString.Append(bugsSql);
sqlString.Append(" WHERE id IN (");
var innerBugsSql = string.Format("SELECT t.id FROM ({0}) t", innerSql);
sqlString.Append(innerBugsSql);
ApplyWhereClause(sqlString, filters);
if (hasFilters)
{
foreach (var filter in filters)
{
sqlString.AddParameterWithValue(GetCleanParameterName(filter.Column), filter.Value);
}
}
sqlString.Append(" ORDER BY ");
sqlString.Append(BuildDynamicOrderByClause(orderBy, sortDirection));
sqlString.Append(" OFFSET @offset ROWS FETCH NEXT @page_size ROWS ONLY)");
int userId = identity.GetUserId();
sqlString.AddParameterWithValue("@ME", userId);
sqlString.AddParameterWithValue("page_size", length > 0 ? length : MaxLength);
sqlString.AddParameterWithValue("offset", start);
DataSet dataSet = DbUtil.get_dataset(sqlString);
var countUnfiltered = Convert.ToInt32(dataSet.Tables[0].Rows[0][0]);
var countFiltered = hasFilters ? Convert.ToInt32(dataSet.Tables[1].Rows[0][0]) : countUnfiltered;
var bugDataTableIndex = hasFilters ? 2 : 1;
return new BugQueryResult
{
CountUnfiltered = countUnfiltered,
CountFiltered = countFiltered,
Data = dataSet.Tables[bugDataTableIndex]
};
}