Пример #1
0
        public HttpResponseMessage PostLogIn([FromBody] User user)
        {
            var resp = new HttpResponseMessage();

            //treba da se provere polja ..
            if (user == null)
            {
                resp.Content = new StringContent("{ \"success\":\"false\", \"message\":\"Please enter your Username and Password!\"}");
                return(resp);
            }
            UserManipulate um = new UserManipulate();

            user = um.LogIn(user.UserName, user.Password);
            if (user != null)
            {
                //create and set cookie in response
                var cookie = new CookieHeaderValue("auth", user.Auth);
                cookie.Expires = DateTimeOffset.Now.AddDays(1);
                //cookie.Domain = Request.RequestUri.Host; ovo je zebavalo
                cookie.Path = "/";

                resp.Headers.AddCookies(new CookieHeaderValue[] { cookie });

                resp.Content = new StringContent("{\"success\":\"true\"}");
                Uri baseUrl = Request.RequestUri;
                resp.Headers.Location = new Uri("http://" + baseUrl.Authority + "/Home/UserHome");

                return(resp);
            }
            resp.Content = new StringContent("{ \"success\":\"false\",  \"message\":\"Wrong Username or Password!\" }");
            return(resp);
        }
Пример #2
0
        public HttpResponseMessage PostUser([FromBody] User user)
        {
            UserManipulate um   = new UserManipulate();
            var            resp = new HttpResponseMessage();

            if (um.UserNameIsFree(user.UserName))
            {
                //moze da se doda kasnije provera podataka
                string userId = um.SaveUser(user);


                //create and set cookie in response
                var cookie = new CookieHeaderValue("auth", user.Auth);
                cookie.Expires = DateTimeOffset.Now.AddDays(1);
                //cookie.Domain = Request.RequestUri.Host; ovo je zebavalo
                cookie.Path = "/";

                resp.Headers.AddCookies(new CookieHeaderValue[] { cookie });

                resp.Content = new StringContent("{\"success\":\"true\"}");

                Uri baseUrl = Request.RequestUri;
                resp.Headers.Location = new Uri("http://" + baseUrl.Authority + "/Home/UserHome");
                //
                ///resp.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = userId }));
            }
            else
            {
                resp.Content = new StringContent("{\"success\":\"false\", \"message\":\"This UserName is used by another user!\"}");
            }
            return(resp);
        }
Пример #3
0
        public void Post([FromBody] Follow follow)
        {
            if (follow == null)
            {
                return;
            }
            UserManipulate um = new UserManipulate();

            um.RemoveFollowing(follow);
        }
Пример #4
0
        public void Post([FromBody] Follow follow) //add new following user
        {
            if (follow == null)
            {
                return;
            }
            UserManipulate um = new UserManipulate();

            um.AddFollowing(follow);
        }
Пример #5
0
        public string GetUserNameAvailability(string username)
        {
            UserManipulate um = new UserManipulate();

            if (um.UserNameIsFree(username))
            {
                return("{ \"success\":\"true\" }");
            }
            else
            {
                return("{ \"success\":\"false\" }");
            }
        }
Пример #6
0
        public Post Post([FromBody] Post post) //add new post (by user with userId)
        {
            if (post == null)
            {
                return(null);
            }
            if (post.Body == null)
            {
                return(null);
            }
            UserManipulate um = new UserManipulate();

            return(um.AddPost(post));
        }
Пример #7
0
        // POST:
        public IEnumerable <Post> GetPosts(string userId) // return user Posts
        {
            UserManipulate um    = new UserManipulate();
            List <Post>    posts = new List <Post>();

            posts = um.GetAllUserPosts(userId, 0, -1);

            if (posts.Count == 0)
            {
                //posts.Add(new Post("", "", "Enter your firist post!"));
                return(null);
            }
            return(posts); // za sad vracam sve postove ali ovde moze da se doda da vrati npr prvix 20 posta
                           //return null;
        }
Пример #8
0
        public ActionResult UserHome()
        {
            ViewBag.Title = "UserHome";
            var cookie = Request.Cookies.Get("auth");

            if (cookie != null)
            {
                UserManipulate um = new UserManipulate();
                if (!um.IsLogedIn(cookie.Value))
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }
Пример #9
0
        // Post: User
        public User GetUser()
        {
            string            userAuth;
            CookieHeaderValue cookie1 = Request.Headers.GetCookies("auth").FirstOrDefault();

            if (cookie1 != null)
            {
                UserManipulate um = new UserManipulate();
                userAuth = cookie1["auth"].Value;

                if (um.IsLogedIn(userAuth))
                {
                    User user = um.getUserIdFromAuthToken(userAuth);
                    user.Password = null;

                    return(user);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Пример #10
0
        // GET: Posts
        public IEnumerable <Post> GetPosts()//return timeLine posts
        {
            UserManipulate um = new UserManipulate();

            return(um.GetTimeLinePosts(0, -1));
        }
Пример #11
0
        // GET: Follower
        public IEnumerable <User> GetFollower(string userId)//get all followers
        {
            UserManipulate um = new UserManipulate();

            return(um.GetAllFollowerUsers(userId));
        }
Пример #12
0
        public void GetUserLogOut(string userId)
        {
            UserManipulate um = new UserManipulate();

            um.LogOut(userId);
        }