예제 #1
0
 private void Login(object param)
 {
     //begin login attempt
     LoadingIconVisible = true;
     ButtonsEnabled     = false;
     ErrorText          = "";
     _serviceClient.LoginAsync(Email, UserPassword.EncryptPassword(Password, Email));
 }
예제 #2
0
        private void UpdatePassword(EditProfileViewModel vm)
        {
            //update the user's password
            UserPassword up = Db.UserPasswords.Where(p => p.UserId == CurrentUser.Id).FirstOrDefault();

            if (up != null && string.IsNullOrEmpty(vm.NewPassword) == false)
            {
                up.Password = UserPassword.EncryptPassword(vm.NewPassword, CurrentUser);
                Db.SaveChanges();
                vm.UpdatePasswordSuccessMessage = "Your password has been successfully updated.";
            }
            else
            {
                ModelState.AddModelError("", "An error occurred while updating your password.  Please try again.  If the problem persists, please contact support at \"[email protected]\".");
            }
        }
예제 #3
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel vm)
        {
            if (ModelState.IsValid)
            {
                OsbideUser user = Db.Users.Where(e => e.Email.ToLower() == vm.EmailAddress.ToLower()).FirstOrDefault();
                if (user != null)
                {
                    if (user.SchoolId == vm.SchoolId && user.InstitutionId == vm.InstitutionId)
                    {
                        Authentication auth        = new Authentication();
                        string         newPassword = auth.GenerateRandomString(7);
                        UserPassword   password    = Db.UserPasswords.Where(up => up.UserId == user.Id).FirstOrDefault();
                        if (password != null)
                        {
                            //update password
                            password.Password = UserPassword.EncryptPassword(newPassword, user);
                            Db.SaveChanges();

                            //send email
                            string             body = "Your OSBIDE password has been reset.\n Your new password is: \"" + newPassword + "\".\n\nPlease change this password as soon as possible.";
                            List <MailAddress> to   = new List <MailAddress>();
                            to.Add(new MailAddress(user.Email));
                            Email.Send("[OSBIDE] Password Reset Request", body, to);
                            vm.PasswordResetRequestComplete = true;
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Account not found.  Please check the supplied email address and institution information.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Account not found.  Please check the supplied email address and institution information.");
                }
            }
            else
            {
                ModelState.AddModelError("", "Account not found.  Please check the supplied email address and institution information.");
            }

            vm.Schools = Db.Schools.ToList();
            return(View(vm));
        }
예제 #4
0
        private void UpdateEmail(EditProfileViewModel vm)
        {
            //Attempt to update email address.
            //Check to make sure email address isn't in use
            OsbideUser user = Db.Users.Where(u => u.Email.CompareTo(vm.NewEmail) == 0).FirstOrDefault();

            if (user == null && string.IsNullOrEmpty(vm.NewEmail) == false)
            {
                //update email address
                CurrentUser.Email = vm.NewEmail;

                //the email address acts as the hash for the user's password so we've got to change that as well
                UserPassword up = Db.UserPasswords.Where(p => p.UserId == CurrentUser.Id).FirstOrDefault();
                up.Password = UserPassword.EncryptPassword(vm.OldPassword, CurrentUser);
                Db.SaveChanges();

                vm.UpdateEmailSuccessMessage = string.Format("Your email has been successfully updated to \"{0}.\"", CurrentUser.Email);
            }
            else
            {
                ModelState.AddModelError("", "The requested email is already in use.");
            }
        }
예제 #5
0
        /// <summary>
        /// This function is responsible for continually asking for status updates from OSBIDE
        /// </summary>
        private void CheckStatus()
        {
            while (IsSendingData == true)
            {
                //this block checks to make sure that our authentication key is up to date
                string webServiceKey = "";
                lock (_cache)
                {
                    webServiceKey = _cache[StringConstants.AuthenticationCacheKey] as string;

                    bool result = false;
                    try
                    {
                        result = _webServiceClient.IsValidKey(webServiceKey);
                    }
                    catch (Exception)
                    {
                    }

                    //if result is false, our key has gone stale.  Try to login again
                    if (result == false)
                    {
                        string userName = _cache[StringConstants.UserNameCacheKey] as string;
                        byte[] passwordBytes = _cache[StringConstants.PasswordCacheKey] as byte[];
                        byte[] encoderKey = _cache[StringConstants.AesKeyCacheKey] as byte[];
                        byte[] encoderVector = _cache[StringConstants.AesVectorCacheKey] as byte[];
                        string password = "";
                        try
                        {
                            password = AesEncryption.DecryptStringFromBytes_Aes(passwordBytes, encoderKey, encoderVector);
                        }
                        catch (Exception)
                        {
                        }
                        if (userName != null && password != null)
                        {
                            webServiceKey = _webServiceClient.Login(userName, UserPassword.EncryptPassword(password, userName));
                            _cache[StringConstants.AuthenticationCacheKey] = webServiceKey;
                        }
                        else
                        {
                            IsSendingData = false;
                        }
                    }
                }

                //this block checks for recent user profile activity
                DateTime lastLocalProfileUpdate = DateTime.MinValue;
                string lastProfileActivityKey = "LastProfileActivity";
                
                //get last cached value
                lock (_cache)
                {
                    if (_cache.Contains(lastProfileActivityKey) == false)
                    {
                        _cache[lastProfileActivityKey] = DateTime.MinValue;
                    }
                    try
                    {
                        lastLocalProfileUpdate = (DateTime)_cache[lastProfileActivityKey];
                    }
                    catch (Exception)
                    {
                        lastLocalProfileUpdate = DateTime.MinValue;
                        _cache.Remove(lastProfileActivityKey);
                    }
                }

                //get last server value
                if(IsSendingData == true)
                {
                    DateTime lastServerProfileUpdate = DateTime.MinValue;
                    try
                    {
                        lastServerProfileUpdate = _webServiceClient.GetMostRecentSocialActivity(webServiceKey);
                    }
                    catch (Exception)
                    {
                        lastServerProfileUpdate = DateTime.MinValue;
                    }

                    if (lastLocalProfileUpdate < lastServerProfileUpdate)
                    {
                        //notify client of new social activity
                        if (ReceivedNewSocialActivity != null)
                        {
                            ReceivedNewSocialActivity(this, EventArgs.Empty);
                        }
                        _cache[lastProfileActivityKey] = lastServerProfileUpdate;
                    }
                }

                Thread.Sleep(new TimeSpan(0, 0, 3, 0, 0));
            }
        }
예제 #6
0
        public ActionResult Create(CreateAccountViewModel vm)
        {
            if (ModelState.IsValid)
            {
                bool userExists           = false;
                bool identificationExists = false;
                ViewBag.UserExistsError     = false;
                ViewBag.SchoolIdExistsError = false;

                //make sure that the email address is unique
                OsbideUser user = Db.Users.Where(u => u.Email.CompareTo(vm.Email) == 0).FirstOrDefault();
                if (user != null)
                {
                    ModelState.AddModelError("", "A user with that email already exists.");
                    userExists = true;
                    ViewBag.UserExistsError = true;
                }

                //make sure that the institution id has not been used for the selected school
                user = (from u in Db.Users
                        where u.SchoolId.CompareTo(vm.User.SchoolId) == 0 &&
                        u.InstitutionId.CompareTo(vm.User.InstitutionId) == 0
                        select u
                        ).FirstOrDefault();
                if (user != null)
                {
                    ModelState.AddModelError("", "There already exists a user at the selected institution with that ID number.");
                    identificationExists        = true;
                    ViewBag.SchoolIdExistsError = true;
                }

                //only continue if we were provided with a unique email and school id
                if (userExists == false && identificationExists == false)
                {
                    vm.User.Email           = vm.Email;
                    vm.User.Id              = 0;
                    vm.User.DefaultCourseId = 1;

                    Db.Users.Add(vm.User);
                    Db.SaveChanges();

                    //add password information
                    UserPassword password = new UserPassword();
                    password.UserId   = vm.User.Id;
                    password.Password = UserPassword.EncryptPassword(vm.Password, vm.User);
                    Db.UserPasswords.Add(password);
                    Db.SaveChanges();

                    //add default feed options
                    UserFeedSetting feedSetting = new UserFeedSetting();
                    feedSetting.UserId = vm.User.Id;
                    foreach (var evt in ActivityFeedQuery.GetSocialEvents())
                    {
                        feedSetting.SetSetting(evt, true);
                    }
                    Db.UserFeedSettings.Add(feedSetting);
                    Db.SaveChanges();

                    //enroll them in OSBIDE 101
                    Db.CourseUserRelationships.Add(new CourseUserRelationship()
                    {
                        UserId = vm.User.Id, CourseId = 1, Role = CourseRole.Student
                    });
                    vm.User.DefaultCourseId = 1;
                    Db.SaveChanges();

                    //log user in
                    Authentication auth = new Authentication();
                    auth.LogIn(vm.User);

                    //redirect to profile page
                    return(RedirectToAction("Index", "Feed"));
                }
            }

            //shouldn't get here unless we received an error
            //call base Create logic
            Create();
            return(View());
        }
예제 #7
0
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            //AC: Explicity load in assemblies.  Necessary for serialization (why?)
            Assembly.Load("OSBIDE.Library");
            Assembly.Load("OSBIDE.Controls");

            //force load awesomium dlls

            /*
             * try
             * {
             *  Assembly.Load("Awesomium.Core, Version=1.7.1.0, Culture=neutral, PublicKeyToken=e1a0d7c8071a5214");
             *  Assembly.Load("Awesomium.Windows.Controls, Version=1.7.1.0, Culture=neutral, PublicKeyToken=7a34e179b8b61c39");
             * }
             * catch (Exception ex)
             * {
             *  _errorLogger.WriteToLog("Error loading awesomium DLLs: " + ex.Message, LogPriority.HighPriority);
             * }
             * */

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                //login toolbar item.
                CommandID   menuCommandID = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideCommand);
                MenuCommand menuItem      = new MenuCommand(OpenLoginScreen, menuCommandID);
                mcs.AddCommand(menuItem);

                //login toolbar menu option.
                CommandID   loginMenuOption     = new CommandID(CommonGuidList.guidOSBIDE_OsbideToolsMenuCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideLoginToolWin);
                MenuCommand menuLoginMenuOption = new MenuCommand(OpenLoginScreen, loginMenuOption);
                mcs.AddCommand(menuLoginMenuOption);

                //activity feed
                CommandID   activityFeedId  = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideActivityFeedTool);
                MenuCommand menuActivityWin = new MenuCommand(ShowActivityFeedTool, activityFeedId);
                mcs.AddCommand(menuActivityWin);

                //activity feed details
                CommandID   activityFeedDetailsId  = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideActivityFeedDetailsTool);
                MenuCommand menuActivityDetailsWin = new MenuCommand(ShowActivityFeedDetailsTool, activityFeedDetailsId);
                mcs.AddCommand(menuActivityDetailsWin);

                //chat window
                CommandID   chatWindowId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideChatTool);
                MenuCommand menuChatWin  = new MenuCommand(ShowChatTool, chatWindowId);
                mcs.AddCommand(menuChatWin);

                //profile page
                CommandID   profileWindowId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideUserProfileTool);
                MenuCommand menuProfileWin  = new MenuCommand(ShowProfileTool, profileWindowId);
                mcs.AddCommand(menuProfileWin);

                //"ask for help context" menu
                CommandID      askForHelpId  = new CommandID(CommonGuidList.guidOSBIDE_ContextMenuCmdSet, (int)CommonPkgCmdIDList.cmdOsbideAskForHelp);
                OleMenuCommand askForHelpWin = new OleMenuCommand(ShowAskForHelp, askForHelpId);
                askForHelpWin.BeforeQueryStatus += AskForHelpCheckActive;
                mcs.AddCommand(askForHelpWin);

                //create account window
                CommandID   createAccountWindowId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideCreateAccountTool);
                MenuCommand menuAccountWin        = new MenuCommand(ShowCreateAccountTool, createAccountWindowId);
                mcs.AddCommand(menuAccountWin);

                //OSBIDE documentation link
                CommandID   documentationId  = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideDocumentationTool);
                MenuCommand documentationWin = new MenuCommand(OpenDocumentation, documentationId);
                mcs.AddCommand(documentationWin);

                //OSBIDE web link
                CommandID   webLinkId  = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideWebLinkTool);
                MenuCommand webLinkWin = new MenuCommand(OpenOsbideWebLink, webLinkId);
                mcs.AddCommand(webLinkWin);

                //generic OSBIDE window
                CommandID   genericId     = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideGenericToolWindow);
                MenuCommand genericWindow = new MenuCommand(ShowGenericToolWindow, genericId);
                mcs.AddCommand(genericWindow);

                //submit assignment command
                CommandID   submitCommand  = new CommandID(CommonGuidList.guidOSBIDE_OsbideToolsMenuCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideSubmitAssignmentCommand);
                MenuCommand submitMenuItem = new MenuCommand(SubmitAssignmentCallback, submitCommand);
                mcs.AddCommand(submitMenuItem);

                //ask the professor window
                //(commented out for Fall 2013 release at instructor request)

                /*
                 * CommandID askProfessorWindowId = new CommandID(GuidList.guidOSBIDE_VSPackageCmdSet, (int)PkgCmdIDList.cmdidOsbideAskTheProfessor);
                 * MenuCommand menuAskProfessorWin = new MenuCommand(ShowAskProfessorTool, askProfessorWindowId);
                 * mcs.AddCommand(menuAskProfessorWin);
                 * */

                // -- Set an event listener for shell property changes
                var shellService = GetService(typeof(SVsShell)) as IVsShell;
                if (shellService != null)
                {
                    ErrorHandler.ThrowOnFailure(shellService.
                                                AdviseShellPropertyChanges(this, out _EventSinkCookie));
                }
            }

            //add right-click context menu to the VS Error List
            DTE2 dte = (DTE2)this.GetService(typeof(SDTE));

            if (dte != null)
            {
                CommandBars cmdBars      = (CommandBars)dte.CommandBars;
                CommandBar  errorListBar = cmdBars[10];

                CommandBarControl osbideControl = errorListBar.Controls.Add(MsoControlType.msoControlButton,
                                                                            System.Reflection.Missing.Value,
                                                                            System.Reflection.Missing.Value, 1, true);
                // Set the caption of the submenuitem
                osbideControl.Caption        = "View Error in OSBIDE";
                _osbideErrorListEvent        = (EnvDTE.CommandBarEvents)dte.Events.get_CommandBarEvents(osbideControl);
                _osbideErrorListEvent.Click += osbideCommandBarEvent_Click;
            }

            //create our web service
            _webServiceClient = new OsbideWebServiceClient(ServiceBindings.OsbideServiceBinding, ServiceBindings.OsbideServiceEndpoint);
            _webServiceClient.LibraryVersionNumberCompleted += InitStepThree_CheckServiceVersionComplete;
            _webServiceClient.LoginCompleted += InitStepTwo_LoginCompleted;
            _webServiceClient.GetMostRecentWhatsNewItemCompleted += GetRecentNewsItemDateComplete;

            //set up local encryption
            if (_cache.Contains(StringConstants.AesKeyCacheKey) == false)
            {
                _encoder.GenerateKey();
                _encoder.GenerateIV();
                _cache[StringConstants.AesKeyCacheKey]    = _encoder.Key;
                _cache[StringConstants.AesVectorCacheKey] = _encoder.IV;
            }
            else
            {
                _encoder.Key = _cache[StringConstants.AesKeyCacheKey] as byte[];
                _encoder.IV  = _cache[StringConstants.AesVectorCacheKey] as byte[];
            }

            //set up user name and password
            _userName = _cache[StringConstants.UserNameCacheKey] as string;
            byte[] passwordBytes = _cache[StringConstants.PasswordCacheKey] as byte[];
            try
            {
                _userPassword = AesEncryption.DecryptStringFromBytes_Aes(passwordBytes, _encoder.Key, _encoder.IV);
            }
            catch (Exception)
            {
            }


            //set up tool window manager
            _manager = new OsbideToolWindowManager(_cache as FileCache, this);

            //set up service logger
            _eventHandler                      = new OsbideEventHandler(this as System.IServiceProvider, EventGenerator.GetInstance());
            _client                            = ServiceClient.GetInstance(_eventHandler, _errorLogger);
            _client.PropertyChanged           += ServiceClientPropertyChanged;
            _client.ReceivedNewSocialActivity += ServiceClientReceivedSocialUpdate;
            UpdateSendStatus();

            //display a user notification if we don't have any user on file
            if (_userName == null || _userPassword == null)
            {
                _hasStartupErrors = true;
                MessageBoxResult result = MessageBox.Show("Thank you for installing OSBIDE.  To complete the installation, you must enter your user information, which can be done by clicking on the \"Tools\" menu and selecting \"Log into OSBIDE\".", "Welcome to OSBIDE", MessageBoxButton.OK);
            }
            else
            {
                //step #1: attempt login
                string hashedPassword = UserPassword.EncryptPassword(_userPassword, _userName);

                try
                {
                    _webServiceClient.LoginAsync(_userName, hashedPassword);
                }
                catch (Exception ex)
                {
                    _errorLogger.WriteToLog("Web service error: " + ex.Message, LogPriority.HighPriority);
                    _hasStartupErrors = true;
                }
            }
        }