Exemplo 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);
        }
Exemplo n.º 2
0
 public JsonResult checkUsernameExists(ValidateAccountRequest req)
 {
     var _db = new ZestorkContainer();
     if (_db.Users.Any(x => x.Username == req.userName))
     {
         return Json(new { code = "402", msg = "username already exists" });
     }
     else
     {
         return Json(new { code = "200", msg = "this is a new username" });
     }
 }
Exemplo n.º 3
0
 public static string getUserType(string username)
 {
     var _db = new ZestorkContainer();
     Users user = _db.Users.SingleOrDefault(x => x.Username == username);
     if (user != null)
     {
         return user.Type;
     }
     else
     {
         return "user";
     }
 }
Exemplo n.º 4
0
 public JsonResult CheckIfUserNewPasswordIsSet()
 {
     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 Users = _db.Users.SingleOrDefault(x => x.Username == userName);
     if (Users.Password.Length == 36)
         return Json(false, JsonRequestBehavior.AllowGet);
     else
         return Json(true, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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);
        }
Exemplo 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 !!!");
        }
Exemplo n.º 8
0
        public JsonResult userTypeInfoAvailable()
        {
            IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization");
            String guid = headerValues.FirstOrDefault();
            guid = guid.Replace("/", "");
            CPSession retVal = TokenManager.getSessionInfo(guid);
            string userName = retVal.getAttributeValue("userName");

            bool userTypeInfoAvailableResponse = false;
            var _db = new ZestorkContainer();
            Users user = _db.Users.SingleOrDefault(x => x.Username == userName);
            if (user.Type == "NA")
                userTypeInfoAvailableResponse = false;
            else
                userTypeInfoAvailableResponse = true;
            return Json(userTypeInfoAvailableResponse, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public JsonResult isUserClient()
        {
            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 user = _db.Users.SingleOrDefault(x => x.Username == userName);
            bool isUserClient = false;
            if (user.Type == "client")
                isUserClient = true;

            return Json(isUserClient, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 11
0
        public JsonResult getUserPageThemeData()
        {
            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);

            return Json(UserPageTheme, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 12
0
        public JsonResult forgetPassword(string id)
        {
            var _db = new ZestorkContainer();
            String guid = Guid.NewGuid().ToString();

            if (_db.Users.Any(x => x.Username == id))
            {
                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.logDbContextException(e);
                    return Json(500, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(404, JsonRequestBehavior.AllowGet);
            }

            return Json(200, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 13
0
        public JsonResult getKeyVal()
        {
            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 UserInfo = _db.Users.SingleOrDefault(x => x.Username == userName);
            Encryption.Encryption EncryptionObj = new Encryption.Encryption();
            string cipherKey = EncryptionObj.getEncryptionKey(UserInfo.Password, UserInfo.guid);

            return Json(new { code = "200", key = cipherKey }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 14
0
 public JsonResult validateAccount(ValidateAccountRequest req)
 {
     var _db = new ZestorkContainer();
     if (_db.ValidateUserKeys.Any(x => x.Username == req.userName && x.guid == req.guid))
     {
         Users User = _db.Users.SingleOrDefault(x => x.Username == req.userName);
         User.isActive = "true";
         try
         {
             _db.SaveChanges();
         }
         catch (DbEntityValidationException e)
         {
             dbContextException.logDbContextException(e);
             throw;
         }
         return Json(new { code = "200", msg = "account validated successfully" });
     }
     else
     {
         return Json(new { code = "402", msg = "Link might be expired" });
     }
 }
Exemplo n.º 15
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;
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
0
        public JsonResult isValidToken(string id)
        {
            var _db = new ZestorkContainer();

            string username = Request.QueryString["username"].ToString();
            username = username.Split('/')[0];

            string password = string.Empty;
            string key = Request.QueryString["key"].ToString();
            key = key.Replace(' ', '+');
            if (TokenManager.isValidSession(id))
            {
                CPSession retVal = TokenManager.getSessionInfo(id);
                string type = retVal.getAttributeValue("type");
                if(type=="client")
                    return Json(new { isValid = true, url = "http://" + Request.Url.Authority + "/Client" }, JsonRequestBehavior.AllowGet);
                else
                    return Json(new { isValid = true, url = "http://" + Request.Url.Authority + "/secure"+type+"Clientcompare"+type=="client" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                Users user = _db.Users.SingleOrDefault(x => x.Username == username);
                if (user != null && user.KeepMeSignedIn != null)
                {
                    if (user.KeepMeSignedIn == "true")
                    {
                        Encryption.Encryption EncryptionObj = new Encryption.Encryption();
                        password = EncryptionObj.getDecryptionValue(key, user.guid);
                        if (password == user.Password)
                        {
                            CPSession session = new CPSession();
                            session.addAttribute("userName", user.Username);
                            session.addAttribute("type", AccountControllerMethods.getUserType(user.Username));
                            bool isPersistent = false; // as of now we have only 1 type of login
                            session.setID(id);
                            TokenManager.CreateSession(session, isPersistent);
                            return Json(new { isValid = true, url = "http://" + Request.Url.Authority + "/secure" }, JsonRequestBehavior.AllowGet);
                        }

                        return Json(new { isValid = false, url = "http://" + Request.Url.Authority + "/secure" }, JsonRequestBehavior.AllowGet);
                    }
                }

                return Json(new { isValid = false, url = "http://" + Request.Url.Authority + "/secure" }, JsonRequestBehavior.AllowGet);
            }
        }
Exemplo n.º 18
0
        public ActionResult unlock()
        {
            var _db = new ZestorkContainer();

            string userName = Request.Form["username"].ToString();
            String password = Request.Form["password"].ToString();
            String id = Request.Form["id"].ToString();
            if (_db.Users.Any(x => x.Username == userName && x.Password == password))
            {
                Users user = _db.Users.SingleOrDefault(x => x.Username == userName && x.isActive == "true");
                if (user != null)
                {
                    user.Locked = "false";
                    try
                    {
                        _db.SaveChanges();
                        try
                        {
                            CPSession retVal = TokenManager.getSessionInfo(id);
                            TokenManager.removeSession(id);// remove session if available.
                        }
                        catch (Exception)
                        {
                            //if session is not available.. leave it.
                        }

                        #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="******"/#/");
                    }
                    catch (DbEntityValidationException e)
                    {
                        dbContextException dbContextException = new dbContextException();
                        dbContextException.logDbContextException(e);
                        throw;
                    }

                }

                Users User = _db.Users.SingleOrDefault(x => x.Username == userName);
                LockedScreenModel userInfo = new LockedScreenModel();
                userInfo.firstName = User.FirstName;
                userInfo.lastName = User.LastName;
                if (User.ImageUrl == "NA" || User.ImageUrl == null)
                    userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg";
                else
                    userInfo.imageUrl = User.ImageUrl;

                if (userInfo.imageUrl.Contains("../../"))
                {
                    userInfo.imageUrl = "../" + userInfo.imageUrl;
                }
                userInfo.message = "Enter Your Password to Unlock !!";
                userInfo.guid = id;
                userInfo.userName = User.Username;
                userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id;
                User.Locked = "true";

                UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName);
                if (pageSetting != null)
                    userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor;
                else
                    userInfo.PageThemeColor = "";

                userInfo.message = "Inactive Account.";
                return View("index", userInfo);
            }
            else
            {
                Users User = _db.Users.SingleOrDefault(x => x.Username == userName);
                LockedScreenModel userInfo = new LockedScreenModel();
                userInfo.firstName = User.FirstName;
                userInfo.lastName = User.LastName;
                if (User.ImageUrl == "NA" || User.ImageUrl == null)
                    userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg";
                else
                    userInfo.imageUrl = User.ImageUrl;

                if (userInfo.imageUrl.Contains("../../"))
                {
                    userInfo.imageUrl = "../" + userInfo.imageUrl;
                }

                userInfo.guid = id;
                userInfo.userName = User.Username;
                userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id;
                User.Locked = "true";

                UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName);
                if (pageSetting != null)
                    userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor;
                else
                    userInfo.PageThemeColor = "";

                userInfo.message = "invalid entry !! try again.";
                return View("index", userInfo);
            }
        }
Exemplo n.º 19
0
        public ActionResult CreateAccount(CreateAccountRequest req)
        {
            logger.Info("new account creation request");
            var _db = new ZestorkContainer();
            String emailRetVal = String.Empty;
            //if user already exists
            if(_db.Users.Any(x=>x.Username==req.userName))
                return Json(new { code="402",msg="User Already Exists" });

            String ID = Guid.NewGuid().ToString();
            var user = new Users
            {
                Username = req.userName,
                Password = req.password,
                Source = req.source,
                isActive = "false",
                Type = req.type,
                guid = Guid.NewGuid().ToString(),
                FirstName = req.firstName,
                LastName = req.lastName,
                gender = "NA",
                ImageUrl = "NA"
            };

            _db.Users.Add(user);

            if (req.referral != null && req.referral != "")
            {
                var referral = new RecommendedBy
                {
                    RecommendedFrom = req.referral,
                    RecommendedTo = req.userName
                };
                _db.RecommendedBies.Add(referral);
            }
            if (req.type == "client")
            {
                var clientDetails = new ClientDetails
                {
                    Username = req.userName,
                    CompanyName = req.CompanyName
                };
                _db.ClientDetails.Add(clientDetails);
            }
            var ValidateUserKey = new ValidateUserKey
            {
                 Username = req.userName,
                 guid = ID
            };

            _db.ValidateUserKeys.Add(ValidateUserKey);

            try
            {
                _db.SaveChanges();
                sendAccountCreationValidationEmail sendAccountCreationValidationEmail = new sendAccountCreationValidationEmail();
                emailRetVal = sendAccountCreationValidationEmail.sendAccountCreationValidationEmailMessage(req.userName, ID,Request);
            }
            catch (DbEntityValidationException e)
            {
                dbContextException.logDbContextException(e);
                throw;
            }

            //Users User = _db.Users.SingleOrDefault(x => x.Username == req.userName);
            //ValidateUserKey key = _db.ValidateUserKeys.SingleOrDefault(x => x.Username == req.userName);

            return Json(new { code="200",msg="successfully created account" });
        }
Exemplo n.º 20
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");
        }
Exemplo n.º 21
0
        public JsonResult details(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();
            detailsEditUserPage detailsEditUserPage = new detailsEditUserPage();
            Users user = _db.Users.SingleOrDefault(x => x.Username == userName && x.isActive == "true");
            bool Autherized = true;
            UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName);
            if (user.Locked == "true")
            {
                //Response.Redirect("/Locked/index/"+guid);
            }

            if (user.Type == "user" || user.Type == "NA")
            {
                Autherized = false;
            }
            detailsEditUserPage.Username = user.Username;
            detailsEditUserPage.isActive = user.isActive;
            detailsEditUserPage.Type = user.Type;
            detailsEditUserPage.Source = user.Source;
            detailsEditUserPage.guid = user.guid;
            detailsEditUserPage.FirstName = user.FirstName;
            detailsEditUserPage.LastName = user.LastName;
            detailsEditUserPage.ImageUrl = user.ImageUrl;
            detailsEditUserPage.gender = user.gender;
            detailsEditUserPage.Locked = Convert.ToBoolean(user.Locked);
            if (user.KeepMeSignedIn != null && user.KeepMeSignedIn == "true")
                detailsEditUserPage.keepMeSignedIn = true;
            else
                detailsEditUserPage.keepMeSignedIn = false;
            if (pageSetting == null)
            {
                pageSetting = new UserPageSetting();
            }
            if (pageSetting.PageThemeColor != null)
                detailsEditUserPage.PageThemeColor = "theme-" + pageSetting.PageThemeColor;
            else
                detailsEditUserPage.PageThemeColor = "";

            if (pageSetting.LayoutWidth != null)
                detailsEditUserPage.pageLayoutWidth = pageSetting.LayoutWidth;
            else
                detailsEditUserPage.pageLayoutWidth = "container-fluid";

            if (pageSetting.TopBar != null)
                detailsEditUserPage.pageTopbar = pageSetting.TopBar;
            else
                detailsEditUserPage.pageTopbar = "";

            if (pageSetting.SideBar != null)
                detailsEditUserPage.pageSidebar = pageSetting.SideBar;
            else
                detailsEditUserPage.pageSidebar = "Default";

            detailsEditUserPage.skillTags = _db.UserSkills.Where(x => x.Username == userName).Select(x => x.Skill).ToList();
            if (detailsEditUserPage.ImageUrl == "NA" || detailsEditUserPage.ImageUrl == null)
                detailsEditUserPage.ImageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg";
            return Json(new { details = detailsEditUserPage, Autherized = Autherized }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 22
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);
            }
        }
Exemplo n.º 23
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
            }
        }
Exemplo n.º 24
0
        //
        // GET: /Locked/
        public ActionResult Index(string id)
        {
            var _db = new ZestorkContainer();
            CPSession retVal = TokenManager.getSessionInfo(id);
            string userName = retVal.getAttributeValue("userName");
            Users User = _db.Users.SingleOrDefault(x => x.Username == userName);
            LockedScreenModel userInfo = new LockedScreenModel();
            userInfo.firstName = User.FirstName;
            userInfo.lastName = User.LastName;
            if (User.ImageUrl == "NA" || User.ImageUrl == null)
                userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg";
            else
                userInfo.imageUrl = User.ImageUrl;

            if (userInfo.imageUrl.Contains("../../"))
            {
                userInfo.imageUrl = "../" + userInfo.imageUrl;
            }
            userInfo.message = "";
            userInfo.guid = id;
            userInfo.userName = User.Username;
            userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id;
            User.Locked = "true";

            UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName);
            if (pageSetting != null)
                userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor;
            else
                userInfo.PageThemeColor = "";

            try
            {
                _db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                dbContextException dbContextException = new dbContextException();
                dbContextException.logDbContextException(e);
                throw;
            }
            return View(userInfo);
        }
Exemplo n.º 25
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;
        }