コード例 #1
0
		public static IEnumerable<Claim> GetClaims(ApplicationUser user)
		{

			List<Claim> claims = new List<Claim>();

			var daysInWork = (DateTime.Now.Date - user.JoinDate).TotalDays;

			if (daysInWork > 90)
			{
				claims.Add(CreateClaim("FTE", "1"));

			}
			else
			{
				claims.Add(CreateClaim("FTE", "0"));
			}

			return claims;
		}
コード例 #2
0
		public async Task<IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel)
		{
			if (!ModelState.IsValid)
			{
				return BadRequest(ModelState);
			}

			var user = new ApplicationUser()
			{
				UserName = createUserModel.Username,
				Email = createUserModel.Email,
				FirstName = createUserModel.FirstName,
				LastName = createUserModel.LastName,
				Level = 3,
				JoinDate = DateTime.Now.Date,
			};

			IdentityResult addUserResult = null;
            try
			{
				addUserResult = await AppUserManager.CreateAsync(user, createUserModel.Password);
			}
			catch (Exception ex)
			{

			}
			

			if (!addUserResult.Succeeded)
			{
				return GetErrorResult(addUserResult);
			}

			// send confirmation email
			var code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id);
			var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code }));
			try
			{
				await AppUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
			}
			catch (Exception ex)
			{

			}


			var locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id }));
			return Created(locationHeader, TheModelFactory.Create(user));
		}