Esempio n. 1
0
        public JsonResult addUsersTag(string id)
        {
            IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization");
            String guid = headerValues.FirstOrDefault();
            guid = guid.Replace("/", "");
            CPSession retVal = TokenManager.getSessionInfo(guid);
            string userName = retVal.getAttributeValue("userName");

            var _db = new ZestorkContainer();
            var userSkillTag = new UserSkills
            {
                Username = userName,
                Skill = id,
                Rating = "0"
            };
            _db.UserSkills.Add(userSkillTag);
            try
            {
                _db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                dbContextException dbContextException = new CommonMethods.dbContextException();
                dbContextException.logDbContextException(e);
                return Json(500, JsonRequestBehavior.AllowGet);
            }
            return Json(200, JsonRequestBehavior.AllowGet);
        }
Esempio n. 2
0
        public LogOnModel Login(string userName, string passwrod, string returnUrl, string keepMeSignedIn)
        {
            var _db = new ZestorkContainer();
            var userData = new LogOnModel();
            if (_db.Users.Any(x => x.Username == userName && x.Password == passwrod))
            {
                Users user = _db.Users.SingleOrDefault(x => x.Username == userName && x.isActive=="true");
                if (user != null)
                {
                    userData.User = new User();
                    //user is already registered
                    userData.User.FirstName = user.FirstName;
                    userData.User.LastName = user.LastName;
                    userData.User.Username = user.Username;
                    userData.User.Gender = user.gender;
                    userData.User.ImageUrl = user.ImageUrl;
                    userData.User.Email = user.Username;
                    try
                    {
                        if (keepMeSignedIn == "true")
                            user.KeepMeSignedIn = "true";
                        else
                            user.KeepMeSignedIn = "false";

                        _db.SaveChanges();
                    }
                    catch (DbEntityValidationException e)
                    {
                        dbContextException dbContextException = new CommonMethods.dbContextException();
                        dbContextException.logDbContextException(e);
                    }
                    userData.User.keepMeSignedIn = user.KeepMeSignedIn;
                    userData.statusCode = "200";

                }
                else
                    userData.statusCode = "403";
            }
            else
                userData.statusCode = "401";
            userData.ReturnUrl = returnUrl;
            return userData;
        }
Esempio n. 3
0
        public JsonResult changeUserPassword(changePasswordRequest req)
        {
            IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization");
            String guid = headerValues.FirstOrDefault();
            guid = guid.Replace("/", "");
            CPSession retVal = TokenManager.getSessionInfo(guid);
            string userName = retVal.getAttributeValue("userName");

            var _db = new ZestorkContainer();
            Users User = _db.Users.SingleOrDefault(x => x.Username == userName);
            User.Password = req.password;
            try
            {
                _db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                dbContextException dbContextException = new CommonMethods.dbContextException();
                dbContextException.logDbContextException(e);
                return Json(500);
            }
            return Json(200);
        }
Esempio n. 4
0
        public JsonResult submitUserPageTopbar(string id)
        {
            IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization");
            String guid = headerValues.FirstOrDefault();
            guid = guid.Replace("/", "");
            CPSession retVal = TokenManager.getSessionInfo(guid);
            string userName = retVal.getAttributeValue("userName");

            var _db = new ZestorkContainer();
            var UserPageTheme = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName);
            if (UserPageTheme == null)
            {
                UserPageTheme = new UserPageSetting
                {
                    Username = userName,
                    TopBar = id
                };
                _db.UserPageSettings.Add(UserPageTheme);
            }
            else
            {
                UserPageTheme.TopBar = id;
            }

            try
            {
                _db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                dbContextException dbContextException = new CommonMethods.dbContextException();
                dbContextException.logDbContextException(e);
                return Json(500, JsonRequestBehavior.AllowGet);
            }
            return Json(200, JsonRequestBehavior.AllowGet);
        }
Esempio n. 5
0
        public JsonResult forgetPassword(string id)
        {
            var _db = new ZestorkContainer();
            String guid = Guid.NewGuid().ToString();
            String guidSession = Request.QueryString["guidSession"].ToString();

            if (_db.Users.Any(x => x.Username == id))
            {
                AccountController AccountController = new AccountController();
                Users UserDetail = _db.Users.SingleOrDefault(x => x.Username == id);
                if (UserDetail.Source == "facebook")
                {
                    UserDetail.Locked = "false";
                    UserDetail.Password = guid;
                    try
                    {
                        _db.SaveChanges();
                        try
                        {
                            TokenManager.removeSession(guidSession);
                        }
                        catch (Exception)
                        {
                            //no need to remove the session if it is invalid...
                        }

                        return Json(210, JsonRequestBehavior.AllowGet); // unreachable code //210 for facebook..
                    }
                    catch (DbEntityValidationException e)
                    {
                        dbContextException dbContextException = new CommonMethods.dbContextException();
                        dbContextException.logDbContextException(e);
                        return Json(500, JsonRequestBehavior.AllowGet); // unreachable code
                    }
                }
                else
                {

                    if (UserDetail != null)
                    {
                        var forgetPasswordDataAlreadyExists = _db.ForgetPasswords.SingleOrDefault(x => x.Username == id);
                        if (forgetPasswordDataAlreadyExists != null)
                            _db.ForgetPasswords.Remove(forgetPasswordDataAlreadyExists);

                        var forgetPasswordData = new ForgetPassword
                        {
                            Username = id,
                            guid = guid
                        };
                        _db.ForgetPasswords.Add(forgetPasswordData);

                        try
                        {
                            _db.SaveChanges();
                            forgetPasswordValidationEmail forgetPasswordValidationEmail = new forgetPasswordValidationEmail();
                            forgetPasswordValidationEmail.sendForgetPasswordValidationEmailMessage(id, guid, Request);
                        }
                        catch (DbEntityValidationException e)
                        {
                            dbContextException dbContextException = new CommonMethods.dbContextException();
                            dbContextException.logDbContextException(e);
                            return Json(500, JsonRequestBehavior.AllowGet);
                        }
                    }
                    else
                    {
                        return Json(404, JsonRequestBehavior.AllowGet);
                    }

                    return Json(200, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json("Username doesn't exists..", JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 6
0
        public LogOnModel Login(string returnUrl, string AbsoluteUri, string oauth_token, string oauth_verifier, string referral,string userType)
        {
            var userData = new LogOnModel();
            var _db = new ZestorkContainer();

            string authLink = string.Empty;
            if (oauth_token != null && oauth_verifier != null)
            {
                var linkedInApiDataResponse = _db.LinkedInAuthApiDatas.SingleOrDefault(x => x.oauth_Token == oauth_token);
                if (linkedInApiDataResponse != null)
                {
                    GetAccessToken(oauth_token, linkedInApiDataResponse.oauth_TokenSecret, oauth_verifier);
                    String UserDetailString = RequestProfile(_oauth.Token, _oauth.TokenSecret, oauth_verifier);
                    var UserDetails = JsonConvert.DeserializeObject<linkedinUserDataWrapper>(Convert.ToString(UserDetailString));
                    _db.LinkedInAuthApiDatas.Attach(linkedInApiDataResponse);
                    _db.LinkedInAuthApiDatas.Remove(linkedInApiDataResponse);
                    //_db.SaveChanges();

                    userData.User = new User();
                    if (_db.Users.Any(x => x.Username == UserDetails.emailAddress))
                    {
                        Users user = _db.Users.SingleOrDefault(x => x.Username == UserDetails.emailAddress);
                        //user is already registered
                        userData.User.FirstName = user.FirstName;
                        userData.User.LastName = user.LastName;
                        userData.User.Username = user.Username;
                        userData.User.Gender = user.gender;
                        userData.User.ImageUrl = user.ImageUrl;
                        userData.statusCode = "200";
                    }
                    else
                    {
                        // add user in database
                        String ID = Guid.NewGuid().ToString();
                        userData.User.FirstName = UserDetails.firstName;
                        userData.User.LastName = UserDetails.lastName;
                        userData.User.Username = UserDetails.emailAddress;
                        try
                        {
                            userData.User.Email = UserDetails.emailAddress;
                        }
                        catch (Exception)
                        {

                            userData.User.Email = "NA";
                        }

                        userData.User.Gender = "NA";
                        userData.User.ImageUrl = "NA";
                        userData.User.Username = UserDetails.emailAddress;
                        var user = new Users
                        {
                            Username = UserDetails.emailAddress,
                            Password = Guid.NewGuid().ToString(),
                            Source = "linkedin",
                            isActive = "true",
                            Type = userType != null ? userType : "NA",
                            guid = Guid.NewGuid().ToString(),
                            FirstName = UserDetails.firstName,
                            LastName = UserDetails.lastName,
                            gender = "NA",
                            ImageUrl = "NA"
                        };

                        _db.Users.Add(user);

                        try
                        {
                            _db.SaveChanges();
                            userData.statusCode = "200";
                        }
                        catch (DbEntityValidationException e)
                        {
                            dbContextException dbContextException = new CommonMethods.dbContextException();
                            dbContextException.logDbContextException(e);
                            throw;
                        }
                    }

                }
            }
            else
            {
                authLink = CreateAuthorization();
                var linkedInApiData = new LinkedInAuthApiData
                {
                    oauth_Token = _oauth.Token,
                    oauth_TokenSecret = _oauth.TokenSecret,
                    oauth_verifier = ""
                };
                _db.LinkedInAuthApiDatas.Add(linkedInApiData);
                try
                {
                    _db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    dbContextException dbContextException = new CommonMethods.dbContextException();
                    dbContextException.logDbContextException(e);
                    throw;
                }
                userData.ReturnUrl = authLink;
            }
            return userData;
        }
Esempio n. 7
0
        public JsonResult UploadToAlbum(String id)
        {
            var _db = new ZestorkContainer();
            CPSession retVal = TokenManager.getSessionInfo(id);
            string userName = retVal.getAttributeValue("userName");
            var user = _db.Users.SingleOrDefault(x => x.Username == userName);
            if (user != null)
            {
                HttpPostedFileBase photo = Request.Files["photo"];
                imageService imageService = new Service.imageService();
                string uploadedImageLink = imageService.imgurUploadImage(photo);
                //string[] imageUrlSplitted = uploadedImageLink.Split('.');
                ////http://i.imgur.com/uFxYj82.jpg
                //string ImgurId = imageUrlSplitted[2];
                //string uploadedImageLinkMedium = imageUrlSplitted[0] + "." + imageUrlSplitted[1] + "." + imageUrlSplitted[2] + "m." + imageUrlSplitted[3];

                //saving medium size image url in db..
                user.ImageUrl = uploadedImageLink;
                try
                {
                    _db.SaveChanges();
                    if (user.Type == "client")
                        Response.Redirect("/Client#/edit");
                    else
                        Response.Redirect("/secure#/edit");
                    return Json(200, JsonRequestBehavior.AllowGet);
                }
                catch (DbEntityValidationException e)
                {
                    dbContextException dbContextException = new CommonMethods.dbContextException();
                    dbContextException.logDbContextException(e);
                    return Json("Internal Server Error Occured !!", JsonRequestBehavior.AllowGet);
                }
            }
            else
                return Json("invalid username !!!");
        }
Esempio n. 8
0
        public ActionResult validateForgetPassword()
        {
            var _db = new ZestorkContainer();
            String guid = Request.QueryString["guid"];
            String username = Request.QueryString["username"];

            if (!_db.Users.Any(x => x.Username == username))
            {
                Response.Redirect("/");
            }
            if(_db.ForgetPasswords.Any(x=>x.Username == username && x.guid == guid))
            {
                var removeForgetPasswordData = _db.ForgetPasswords.SingleOrDefault(x => x.Username == username);
                _db.ForgetPasswords.Remove(removeForgetPasswordData);

                var UserData = _db.Users.SingleOrDefault(x => x.Username == username);
                UserData.Password = Guid.NewGuid().ToString();
                UserData.Locked = "false";
                try
                {
                    _db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    dbContextException dbContextException = new CommonMethods.dbContextException();
                    dbContextException.logDbContextException(e);
                }

                #region Session
                CPSession session = new CPSession();
                session.addAttribute("userName", username);
                bool isPersistent = false; // as of now we have only 1 type of login
                TokenManager.CreateSession(session, isPersistent);
                #endregion

                Response.Redirect("/Account/welcome?guid=" + session.getID() + "&username="******"/#/");
            }
            else
            {
                Response.Redirect("/#/forgetpassword");
            }
            return View("Home","Index");
        }
Esempio n. 9
0
        public JsonResult logout(string id)
        {
            try
            {
                var _db = new ZestorkContainer();

                CPSession retVal = TokenManager.getSessionInfo(id);
                if (retVal != null)
                {
                    string userName = retVal.getAttributeValue("userName");
                    Users user = _db.Users.SingleOrDefault(x => x.Username == userName);
                    if (user != null)
                    {
                        try
                        {
                            user.KeepMeSignedIn = "false";
                            _db.SaveChanges();
                        }
                        catch (DbEntityValidationException e)
                        {
                            dbContextException dbContextException = new CommonMethods.dbContextException();
                            dbContextException.logDbContextException(e);
                        }

                    }
                    TokenManager.removeSession(id);
                }
                else
                {
                    string username = Request.QueryString["username"].ToString();
                    if (username != null || username != "")
                    {
                        username = username.Split('/')[0];
                        Users user = _db.Users.SingleOrDefault(x => x.Username == username);
                        if (user != null && user.KeepMeSignedIn != null)
                        {
                            if (user.KeepMeSignedIn == "true")
                            {
                                try
                                {
                                    user.KeepMeSignedIn = "false";
                                    _db.SaveChanges();
                                }
                                catch (DbEntityValidationException e)
                                {
                                    dbContextException dbContextException = new CommonMethods.dbContextException();
                                    dbContextException.logDbContextException(e);
                                }
                            }
                        }
                    }
                }
                Response.Redirect("/");
                return Json(200, JsonRequestBehavior.AllowGet); // unreachable code
            }
            catch (DbEntityValidationException e)
            {
                dbContextException dbContextException = new CommonMethods.dbContextException();
                dbContextException.logDbContextException(e);
                Response.Redirect("/");
                return Json(500, JsonRequestBehavior.AllowGet); // unreachable code
            }
        }
Esempio n. 10
0
        public LogOnModel Login(string returnUrl, string code, string referral,string userType)
        {
            var _db = new ZestorkContainer();
            var userData = new LogOnModel();
            string app_id = "";
            string app_secret = "";
            app_id = ConfigurationManager.AppSettings["googleAppID"].ToString();
            app_secret = ConfigurationManager.AppSettings["googleAppSecret"].ToString();
            //if (returnUrl.Contains("zestork.pcongo"))
            //{
            //    app_id = ConfigurationManager.AppSettings["googleAppIDZestork"].ToString();
            //    app_secret = ConfigurationManager.AppSettings["googleAppSecretZestork"].ToString();
            //}
            //else
            //{
            //    app_id = ConfigurationManager.AppSettings["googleAppID"].ToString();
            //    app_secret = ConfigurationManager.AppSettings["googleAppSecret"].ToString();
            //}

            string scope = "email%20profile";

            if (code == null)
            {
                userData.ReturnUrl = (string.Format(
                    "https://accounts.google.com/o/oauth2/auth?scope={0}&state=%2Fprofile&redirect_uri={1}&response_type=code&client_id={2}&approval_prompt=force",
                    scope, returnUrl, app_id));
                logger.Info(userData.ReturnUrl);
                return userData;
            }
            else
            {
                string access_token = getGoogleAuthToken(returnUrl, scope, code, app_id, app_secret);
                String URI = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + access_token;
                logger.Info(URI);
                WebClient webClient = new WebClient();
                Stream stream = webClient.OpenRead(URI);
                string googleUserDetailString;

                /*I have not used any JSON parser because I do not want to use any extra dll/3rd party dll*/
                using (StreamReader br = new StreamReader(stream))
                {
                    googleUserDetailString = br.ReadToEnd();
                }
                var googleUserDetails = JsonConvert.DeserializeObject<googleUserDetails>(Convert.ToString(googleUserDetailString));
                userData.User = new User();
                if (_db.Users.Any(x => x.Username == googleUserDetails.email))
                {
                    Users user = _db.Users.SingleOrDefault(x => x.Username == googleUserDetails.email);
                    //user is already registered
                    userData.User.FirstName = user.FirstName;
                    userData.User.LastName = user.LastName;
                    userData.User.Username = user.Username;
                    userData.User.Gender = user.gender;
                    userData.User.ImageUrl = user.ImageUrl;
                    userData.statusCode = "200";
                }
                else
                {
                    // add user in database
                    String ID = Guid.NewGuid().ToString();

                    userData.User.FirstName = googleUserDetails.given_name;
                    userData.User.LastName = googleUserDetails.family_name;
                    try
                    {
                        userData.User.Username = googleUserDetails.email;
                        userData.User.Email = googleUserDetails.email;
                    }
                    catch (Exception)
                    {
                        userData.User.Username = "******";
                        userData.User.Email = "NA";
                    }
                    try
                    {
                        userData.User.Gender = googleUserDetails.gender;
                    }
                    catch (Exception)
                    {
                        userData.User.Gender = "NA";
                        throw;
                    }

                    try
                    {
                        userData.User.ImageUrl = googleUserDetails.picture;
                    }
                    catch (Exception)
                    {
                        userData.User.ImageUrl = "NA";

                    }
                    if (userData.User.Gender == null)
                        userData.User.Gender = "NA";
                    logger.Info(JsonConvert.SerializeObject(userData));
                    var user = new Users
                    {
                        Username = userData.User.Email,
                        Password = Guid.NewGuid().ToString(),
                        Source = "google",
                        isActive = "true",
                        Type = userType != null ? userType : "NA",
                        guid = Guid.NewGuid().ToString(),
                        FirstName = userData.User.FirstName,
                        LastName = userData.User.LastName,
                        gender = userData.User.Gender,
                        ImageUrl = userData.User.ImageUrl,
                    };

                    _db.Users.Add(user);

                    try
                    {
                        _db.SaveChanges();
                        userData.statusCode = "200";
                    }
                    catch (DbEntityValidationException e)
                    {
                        dbContextException dbContextException = new CommonMethods.dbContextException();
                        dbContextException.logDbContextException(e);
                        throw;
                    }
                }
            }
            return userData;
        }
Esempio n. 11
0
        private LogOnModel checkFacebookAuthorization(string returnUrl, string code, string userType)
        {
            var userData = new LogOnModel();
            try
            {
                var _db = new ZestorkContainer();

                string app_id = string.Empty;
                string app_secret = string.Empty;

                app_id = ConfigurationManager.AppSettings["FacebookAppID"].ToString();
                app_secret = ConfigurationManager.AppSettings["FacebookAppSecret"].ToString();

                string scope = "";
                if (code == null)
                {
                    userData.ReturnUrl = (string.Format(
                        "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                        app_id, returnUrl, scope));

                    return userData;
                }
                else
                {

                    string access_token = getFacebookAuthToken(returnUrl, scope, code,app_id,app_secret);
                    var client = new FacebookClient(access_token);
                    dynamic me = client.Get("me");
                    String userName = Convert.ToString(me.username);
                    userData.User = new User();
                    if (_db.Users.Any(x => x.Username == userName + "@facebook.com"))
                    {
                        Users user = _db.Users.SingleOrDefault(x => x.Username == userName + "@facebook.com");
                        //user is already registered
                        userData.User.FirstName = user.FirstName;
                        userData.User.LastName = user.LastName;
                        userData.User.Username = user.Username;
                        userData.User.Gender = user.gender;
                        userData.User.ImageUrl = user.ImageUrl;
                        userData.statusCode = "200";
                    }
                    else
                    {
                        // add user in database
                        String ID = Guid.NewGuid().ToString();
                        String ImageUrl = FacebookService.GetPictureUrl(userName);
                        userData.User.FirstName = me.first_name;
                        userData.User.LastName = me.last_name;
                        userData.User.Username = me.username;
                        userData.User.ImageUrl = ImageUrl;
                        userData.User.Username = userName + "@facebook.com";
                        var user = new Users
                        {
                            Username = userName + "@facebook.com",
                            Password = Guid.NewGuid().ToString(),
                            Source = "facebook",
                            isActive = "true",
                            Type = userType!=null?userType:"NA",
                            guid = Guid.NewGuid().ToString(),
                            FirstName = me.first_name,
                            LastName = me.last_name,
                            gender = "NA",
                            ImageUrl = ImageUrl
                        };

                        _db.Users.Add(user);

                        try
                        {
                            _db.SaveChanges();
                            userData.statusCode = "200";
                        }
                        catch (DbEntityValidationException e)
                        {
                            dbContextException dbContextException = new CommonMethods.dbContextException();
                            dbContextException.logDbContextException(e);
                            throw;
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                logger.Error("facebook login error", ex);
                throw;
            }

            return userData;
        }