示例#1
0
		private Yield SetContext(DreamContext aContext, DreamMessage aRequest, Result<DreamMessage> aResponse)
		{
			Context ctx = new Context(theFactory.GetInstance(aContext, aRequest));

			//TODO: fix this, find real auth
			string username, password;
			if (!HttpUtil.GetAuthentication(aContext.Uri, aRequest.Headers, out username, out password))
			{
				aResponse.Return(DreamMessage.AccessDenied("foiremuses api", "no auth"));
				yield break;
			}

			Result<IUser> user;
			yield return user = ctx.Instance.UserController.Retrieve(username, new Result<IUser>());
			if (user.Value == null)
			{
				aResponse.Return(DreamMessage.AccessDenied("foiremuses api", "no auth"));
				yield break;
			}
			if (user.Value.IsAdmin)
			{
				if (aRequest.Headers[FOIREMUSES_IMPERSONATE_HEADER] != null)
				{
					//act like real user
					ctx.User = ctx.Instance.UserController.Retrieve(aRequest.Headers[FOIREMUSES_IMPERSONATE_HEADER], new Result<IUser>()).Wait();
				}
				else
				{
					ctx.User = user.Value;
				}
			}
			else
			{
				ctx.User = user.Value;
			}
			ctx.AttachToCurrentTaskEnv();
			//create context and attach
			aResponse.Return(aRequest);
			yield break;
		}
		public void Setup()
		{
			Context context = new Context(theInstanceFactory.GetDefaultInstance()); // TODO
			context.User = context.Instance.UserController.Retrieve("danny",new Result<IUser>()).Wait();
			context.AttachToCurrentTaskEnv();
		}
		public void Setup()
		{
			Context context = new Context(theInstanceFactory.GetDefaultInstance()); // TODO
			context.AttachToCurrentTaskEnv();
		}