示例#1
0
        public ActionResult RemoveNotifications(string id)
        {
            User user;

            using (AllUsersRepository usersRep = new AllUsersRepository())
            {
                user = usersRep.GetList().SingleOrDefault(x => x.NotificationCode == id);
                if (user == null)
                {
                    return(Error(Loc.Dic.error_user_not_found));
                }

                user.NotificationEmail = null;
                if (usersRep.Update(user) == null)
                {
                    return(Error(Loc.Dic.error_database_error));
                }
            }

            ViewBag.Title   = Loc.Dic.RemoveNotifications;
            ViewBag.Message = Loc.Dic.NotificationsWereRemoved;
            ViewBag.Align   = "right";
            return(View());
        }
示例#2
0
        private LogInResult ResponseIntoUser(IAuthenticationResponse response)
        {
            LogInResult logInResult = new LogInResult();
            logInResult.IsAuthenticated = true;

            var fetchResponse = response.GetExtension<FetchResponse>();
            if (fetchResponse != null)
            {
                logInResult.User = new OpenIdUser(fetchResponse, response.ClaimedIdentifier);

                using (AllUsersRepository userRep = new AllUsersRepository())
                using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                {
                    User user = userRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);
                    if (user != null)
                    {
                        if (user.IsActive)
                        {
                            if (user.FirstName != logInResult.User.FirstName || user.LastName != logInResult.User.LastName)
                            {
                                user.FirstName = logInResult.User.FirstName;
                                user.LastName = logInResult.User.LastName;
                                userRep.Update(user);
                            }

                            logInResult.IsRegistered = true;
                            logInResult.User.UserId = user.Id;
                            return logInResult;
                        }
                        else
                        {
                            logInResult.IsRegistered = false;
                            logInResult.IsCanceled = true;
                            logInResult.User.UserId = user.Id;
                            return logInResult;
                        }
                    }
                    else
                    {
                        PendingUser pendingUser = pendingUserRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);

                        if (pendingUser != null)
                        {
                            User newUser = new User()
                            {
                                CompanyId = pendingUser.CompanyId,
                                Email = logInResult.User.Email,
                                FirstName = logInResult.User.FirstName,
                                LastName = logInResult.User.LastName,
                                CreationTime = DateTime.Now,
                                LastLogInTime = DateTime.Now,
                                Roles = pendingUser.Roles,
                                LanguageId = pendingUser.LanguageId,
                                IsActive = true
                            };

                            if (!userRep.Create(newUser))
                                return logInResult;

                            logInResult.User.UserId = newUser.Id;
                            pendingUserRep.Delete(pendingUser.Id);

                            logInResult.IsNewUser = true;
                            logInResult.IsRegistered = true;
                            return logInResult;
                        }
                        else
                        {
                            return logInResult;
                        }
                    }
                }
            }
            else
            {
                return logInResult;
            }
        }
示例#3
0
        public ActionResult RemoveNotifications(string id)
        {
            User user;
            using (AllUsersRepository usersRep = new AllUsersRepository())
            {
                user = usersRep.GetList().SingleOrDefault(x => x.NotificationCode == id);
                if (user == null) return Error(Loc.Dic.error_user_not_found);

                user.NotificationEmail = null;
                if (usersRep.Update(user) == null) return Error(Loc.Dic.error_database_error);
            }

            ViewBag.Title = Loc.Dic.RemoveNotifications;
            ViewBag.Message = Loc.Dic.NotificationsWereRemoved;
            ViewBag.Align = "right";
            return View();
        }
示例#4
0
        private LogInResult ResponseIntoUser(IAuthenticationResponse response)
        {
            LogInResult logInResult = new LogInResult();

            logInResult.IsAuthenticated = true;

            var fetchResponse = response.GetExtension <FetchResponse>();

            if (fetchResponse != null)
            {
                logInResult.User = new OpenIdUser(fetchResponse, response.ClaimedIdentifier);

                using (AllUsersRepository userRep = new AllUsersRepository())
                    using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                    {
                        User user = userRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);
                        if (user != null)
                        {
                            if (user.IsActive)
                            {
                                if (user.FirstName != logInResult.User.FirstName || user.LastName != logInResult.User.LastName)
                                {
                                    user.FirstName = logInResult.User.FirstName;
                                    user.LastName  = logInResult.User.LastName;
                                    userRep.Update(user);
                                }

                                logInResult.IsRegistered = true;
                                logInResult.User.UserId  = user.Id;
                                return(logInResult);
                            }
                            else
                            {
                                logInResult.IsRegistered = false;
                                logInResult.IsCanceled   = true;
                                logInResult.User.UserId  = user.Id;
                                return(logInResult);
                            }
                        }
                        else
                        {
                            PendingUser pendingUser = pendingUserRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);

                            if (pendingUser != null)
                            {
                                User newUser = new User()
                                {
                                    CompanyId     = pendingUser.CompanyId,
                                    Email         = logInResult.User.Email,
                                    FirstName     = logInResult.User.FirstName,
                                    LastName      = logInResult.User.LastName,
                                    CreationTime  = DateTime.Now,
                                    LastLogInTime = DateTime.Now,
                                    Roles         = pendingUser.Roles,
                                    LanguageId    = pendingUser.LanguageId,
                                    IsActive      = true
                                };


                                if (!userRep.Create(newUser))
                                {
                                    return(logInResult);
                                }

                                logInResult.User.UserId = newUser.Id;
                                pendingUserRep.Delete(pendingUser.Id);

                                logInResult.IsNewUser    = true;
                                logInResult.IsRegistered = true;
                                return(logInResult);
                            }
                            else
                            {
                                return(logInResult);
                            }
                        }
                    }
            }
            else
            {
                return(logInResult);
            }
        }