I find myself in several place updating the user.webstatus field so I would like to create my own function to do this in a class file so I can just call this instead.
Here is my current code
case SignInStatus.Success:
var finduserid = manager.FindByName(textUsername.Value).Id;
var isadmin = manager.IsInRole(finduserid, "Admin");
var currentUser = manager.FindById(finduserid);
if (isadmin)
{
Response.Redirect("~/pages/admin/adminland.aspx");
}
else
{
// check for first login
var empty = UtilsString.IsEmpty(currentUser.firstLogin.Trim().ToUpper());
if (!empty)
{
if (currentUser.firstLogin.Trim().ToUpper() == "Y")
{
currentUser.webStatus = "Live";
manager.Update(currentUser);
Response.Redirect("~/account/managepassword.aspx");
}
else
{
Response.Redirect("~/pages/userland.aspx");
}
}
}
II have created this method. But I cant create Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); in the class file so I am a bit confused as to how this is done correctly.
///<method>
///Update the users webstatus field, pass userid and numeric
/// 1 - Live
/// 2 - Logged In
/// 3 - Invitation Sent
///<method>
public IdentityResult SetUserWebstatus(string userID,int Status,ApplicationUserManager applicationUserManager)
{
string statusname = "";
var user = applicationUserManager.FindById(userID);
switch (Status)
{
case 1:
statusname = "Live";
break;
case 2:
statusname = "Logged In";
break;
case 3:
statusname = "Invitation Sent";
break;
default:
statusname = "";
break;
}
user.webStatus = statusname;
var result=applicationUserManager.Update(user);
return result;
}
Please can you help point me in the right direction so I can do this correctly.
Seems like a design issue. Perhaps the status should be a claim that drives security or code access. Or maybe use an enumeration since the code converts an int to a string constant which is what an enumeration is for.
Member
7 Points
35 Posts
Identity - returning custom user properties in custom method
Jul 04, 2018 02:49 PM|skyblue28|LINK
I find myself in several place updating the user.webstatus field so I would like to create my own function to do this in a class file so I can just call this instead.
Here is my current code
II have created this method. But I cant create Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); in the class file so I am a bit confused as to how this is done correctly.
Please can you help point me in the right direction so I can do this correctly.
All-Star
53081 Points
23652 Posts
Re: Identity - returning custom user properties in custom method
Jul 04, 2018 03:00 PM|mgebhard|LINK
Seems like a design issue. Perhaps the status should be a claim that drives security or code access. Or maybe use an enumeration since the code converts an int to a string constant which is what an enumeration is for.