public HttpResponseMessage GetProfileField(string username, string field)
        {
            IUser user = null;

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(field))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new uError("Not Found", 404)));
            }
            else
            {
                user = _membershipService.GetUser(username);
            }
            if (user == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NoContent));
            }

            Contrib.Foundation.UserProfile.OData.Profile profile = new Contrib.Foundation.UserProfile.OData.Profile(user, Request, null);

            switch (field)
            {
            case "FirstName":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.FirstName));

            case "Email":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.Email));

            case "Username":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.Username));

            case "LastName":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.LastName));

            case "WebSite":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.WebSite));

            case "Bio":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.Bio));

            case "Location":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.Location));

            case "link":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.link));

            case "Type":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.Type));

            case "Id":
                return(Request.CreateResponse(HttpStatusCode.OK, profile.Id));
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public HttpResponseMessage LoginFacebook(LoginFB login)
        {
            string Hash = string.Empty;
            IUser  user = ValidateLogonFacebook(login, out Hash);

            if (user == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, new uError("User not authorized", 401)));
            }

            _authenticationService.SignIn(user, false);
            _userEventHandler.LoggedIn(user);

            Contrib.Foundation.UserProfile.OData.Profile profile = new Contrib.Foundation.UserProfile.OData.Profile(user, Request, Hash);
            return(Request.CreateResponse(HttpStatusCode.OK, profile));
        }
Exemplo n.º 3
0
        public HttpResponseMessage Login(Login login)
        {
            IUser user = _orchardServices.WorkContext.CurrentUser;

            ApplicationRecord apprecord = _applicationsService.GetApplicationByKey(login.ApiKey);

            if (apprecord == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new uError("Not Found", 404)));
            }

            if (user != null)
            {
                IUser newUser = ValidateLogOn(login);
                if (newUser != null && newUser.Id == user.Id)
                {
                    Contrib.Foundation.UserProfile.OData.Profile profile = new Contrib.Foundation.UserProfile.OData.Profile(user, Request, _loginsService.GetHash(user.As <UserProfilePart>(), apprecord));
                    _orchardServices.WorkContext.HttpContext.Session["doticca_aid"] = apprecord.Id;
                    return(Request.CreateResponse(HttpStatusCode.OK, profile));
                }
                else
                {
                    LogOut();
                }
            }
            user = ValidateLogOn(login);
            if (user != null)
            {
                UserProfilePart profilePart = user.As <UserProfilePart>(); //_profileService.Get(user).As<UserProfilePart>();
                _profileService.CreateUserForApplicationRecord(profilePart, apprecord);
                _authenticationService.SignIn(user, false);
                _userEventHandler.LoggedIn(user);
                string newHash = login.Hash;
                if (string.IsNullOrWhiteSpace(newHash))
                {
                    newHash = _loginsService.CreateHash(profilePart, apprecord);
                }

                Contrib.Foundation.UserProfile.OData.Profile profile = new Contrib.Foundation.UserProfile.OData.Profile(user, Request, newHash);
                _orchardServices.WorkContext.HttpContext.Session["doticca_aid"] = apprecord.Id;
                return(Request.CreateResponse(HttpStatusCode.OK, profile));
            }
            _orchardServices.WorkContext.HttpContext.Session.Remove("doticca_aid");
            return(Request.CreateResponse(HttpStatusCode.Unauthorized, new uError("User not authorized", 401)));
        }
        public HttpResponseMessage GetProfile(string username = null)
        {
            IUser user = null;

            if (string.IsNullOrWhiteSpace(username))
            {
                user = _orchardServices.WorkContext.CurrentUser;
            }
            else
            {
                user = _membershipService.GetUser(username);
            }
            if (user == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NoContent));
            }

            Contrib.Foundation.UserProfile.OData.Profile profile = new Contrib.Foundation.UserProfile.OData.Profile(user, Request, null);
            return(Request.CreateResponse(HttpStatusCode.OK, profile));
        }