示例#1
0
        /// <summary>获取用户列表 </summary>
        /// <param name="nameValues">列表参数</param>
        /// <param name="page">分页信息</param>
        /// <returns>用户实体集合</returns>
        public List <FlightAlarmAddressee> GetList(NameValueCollection nameValues, DataPage page)
        {
            List <FlightAlarmAddressee> addresseeList = new List <FlightAlarmAddressee>();

            addresseeList = UserPersistence.GetList(nameValues, page);
            return(addresseeList);
        }
        public static bool AuthenticateUser(Credential credential, HttpSessionStateBase httpSessionStateBase)
        {
            httpSessionStateBase["LoggedIn"]   = false;//comment2
            httpSessionStateBase["IsAdmin"]    = false;
            httpSessionStateBase["IsProvider"] = false;
            User user = UserPersistence.GetUser(credential.UserId);

            if (user == null)
            {
                System.Diagnostics.Debug.WriteLine("Nulllll user ");

                return(false);
            }
            String pHash = EncryptionManager.EncodePassword(credential.Password, user.Salt);

            System.Diagnostics.Debug.WriteLine("realOne: " + EncryptionManager.EncodePassword("sa", user.Salt));
            System.Diagnostics.Debug.WriteLine("phash: " + pHash);
            System.Diagnostics.Debug.WriteLine("user passsHash: " + user.PasswordHash);
            if (pHash != user.PasswordHash)
            {
                return(false);
            }
            else
            {
                httpSessionStateBase["LoggedIn"]   = true;
                httpSessionStateBase["IsAdmin"]    = user.IsAdmin;
                httpSessionStateBase["IsProvider"] = user.IsProvider;
                return(true);
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public MethodResponse <Guid[]> CreateUsers(User[] users)
        {
            List <Guid>             guids       = new List <Guid>();
            MethodResponse <Guid[]> returnCodes = new MethodResponse <Guid[]>();

            foreach (var user in users)
            {
                try
                {
                    using (TransactionScope transactionScope = new TransactionScope())
                    {
                        guids.Add(UserPersistence.AddUser(user, null));
                        transactionScope.Complete();
                    }
                }
                catch (Exception exception)
                {
                    EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
                    returnCodes.AddError(exception, 0);
                    guids.Add(Guid.Empty);
                }
            }
            returnCodes.Result = guids.ToArray();
            return(returnCodes);
        }
示例#4
0
        // GET: api/User/5
        public User Get(long id)
        {
            UserPersistence up   = new UserPersistence();
            User            user = up.getUser(id);

            return(user);
        }
示例#5
0
        /// <summary>
        /// Modify a specific user by username
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        // PUT: api/User/eng_same7
        public HttpResponseMessage Put(long UserID, [FromBody] User value)
        {
            bool recordExisted = false;
            User UserData      = new User()
            {
                UserID    = UserID,
                Username  = value.Username,
                FirstName = value.FirstName,
                LastName  = value.LastName,
                Email     = value.Email,
                Password  = value.Password
            };

            recordExisted = UserPersistence.UpdateUser(UserData);


            HttpResponseMessage response;

            if (recordExisted)
            {
                // !Comment: return 402 -> record found with no content.
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                // !Comment: return 404 -> record not found.
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }
示例#6
0
        /// <summary>
        /// Get a specific user by his\her username
        /// </summary>
        /// <param name="Username">Username to check for</param>
        /// <returns></returns>
        // GET: api/User/?Username=
        public User Get(string Username)
        {
            User udtResult  = new User();
            User ResultUser = UserPersistence.GetUser(Username);

            if (Request.Headers.Contains("Password"))
            {
                string Password = Request.Headers.GetValues("Password").First();
            }

            if (ResultUser != null)
            {
                udtResult.UserID    = ResultUser.UserID;
                udtResult.Username  = ResultUser.Username;
                udtResult.FirstName = ResultUser.FirstName;
                udtResult.LastName  = ResultUser.LastName;
                udtResult.Email     = ResultUser.Email;
                udtResult.Password  = ResultUser.Password;
            }
            else
            {
                /*To be Changed*/
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            return(ResultUser);
        }
示例#7
0
        public ActionResult AddComment(Comment comment, String sTitle)
        {
            System.Diagnostics.Debug.WriteLine("sesss" + Session["LoggedIn"]);
            if (Session["LoggedIn"] == null || Session["LoggedIn"].Equals(false) || Session["LoggedIn"].ToString().Length == 0)
            {
                TempData["commentAdded"] = "Please Log in.";
                return(View(comment));
            }
            comment.Writer    = UserPersistence.GetUser(Session["userId"].ToString());
            comment.CommentId = CommentPersistence.getMaxId() + 1;
            System.Diagnostics.Debug.WriteLine("***" + sTitle);
            comment.Service = ServicePersistence.GetService(sTitle);
            bool?acceptible = false;

            acceptible = CommentManager.AddNewComment(comment);
            if ((acceptible != null))
            {
                if (acceptible == true)
                {
                    TempData["commentAdded"] = "Comment is added successfully.";
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    TempData["commenteAdded"] = "Comment could not be added.";
                    return(View(comment));
                }
            }
            else
            {
                TempData["commentAdded"] = "Comment could not be added.";
                return(View(comment));
            }
        }
示例#8
0
 /*
  * Transaction: Delete an user from the database
  * Returns true if the user exists in the database and
  * it was successfully deleted.
  */
 public static bool DeleteUser(User delUser)
 {
     if (UserPersistence.getUserDB(delUser) == null)
     {
         return(false);
     }
     return(UserPersistence.DeleteUser(delUser));
 }
示例#9
0
        /// <summary>
        /// Adds the new user into the database.
        /// </summary>
        /// <param name="cr">Credentials for the new user.</param>
        /// <param name="baseState"></param>
        /// <returns>Boolean value whether the transaction is happened or not.</returns>
        public static bool SignUpUser(Credential cr, HttpSessionStateBase baseState)
        {
            baseState["LoggedIn"] = false;
            baseState["IsAdmin"]  = false;


            return(UserPersistence.AddUser(cr));
        }
示例#10
0
        /*
         * Transaction: Update an user in the database
         * Returns true if the user exists in the database and
         * it was successfully changed.
         */
        public static bool ChangeUser(User changeUser)
        {
            if (UserPersistence.getUserDB(changeUser) == null)
            {
                return(false);
            }

            return(UserPersistence.UpdateUserName(changeUser));
        }
示例#11
0
        public ActionResult ProfilePage()
        {
            User user = UserPersistence.GetUser(Session["UserId"].ToString());

            if (user != null && user.IsAdmin)
            {
                return(RedirectToAction("AdminPage", "Admin"));
            }

            return(View(user));
        }
        public ArrayList GetSearch(string text)
        {
            UserPersistence pp = new UserPersistence();
            var             p  = pp.searchUser(text);

            if (p == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            return(p);
        }
        // GET: api/Person/5
        public User Get(String id)
        {
            UserPersistence pp = new UserPersistence();
            User            p  = pp.getUser(id);

            if (p == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            return(p);
        }
示例#14
0
        public ActionResult ChangeUser(int id)
        {
            User user = UserPersistence.getUserID(id);

            if (user == null)
            {
                return(HttpNotFound());
            }
            Session["user"] = user;
            return(View("ChangeUser", user));
        }
示例#15
0
        /// <summary>根据输入信息异步获取数据姓名+工号</summary>
        /// <param name="name">前台输入信息</param>
        /// <returns>搜索结果List</returns>
        public List <FlightAlarmAddressee> GetAjaxList(string name = null)
        {
            List <FlightAlarmAddressee> result = null;
            var       allList     = UserPersistence.GetAllList();
            const int SelectCount = 30;

            result = !string.IsNullOrEmpty(name)
                ? allList.Where(t => t.FAAName.Contains(name.Trim())).Take(SelectCount).ToList()
                : allList.Take(SelectCount).ToList();
            return(result);
        }
示例#16
0
        /// <summary>
        /// Create/Save a new user
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        // POST: api/User
        public HttpResponseMessage Post([FromBody] User Value)
        {
            long id;

            id = UserPersistence.SaveUser(Value);

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);

            // !Comment: This is used to set the location of the posted id in the header after the post is done.
            response.Headers.Location = new Uri(Request.RequestUri, string.Format("user/{0}", id));
            return(response);
        }
        public Persistence(Uri endpointUri, string primaryKey, string databaseId)
        {
            _databaseId  = databaseId;
            _endpointUri = endpointUri;
            _primaryKey  = primaryKey;

            _client = new DocumentClient(endpointUri, primaryKey);
            _client.OpenAsync();

            Samples = new SamplePersistence(_client, _databaseId);
            Users   = new UserPersistence(_client, _databaseId);
        }
示例#18
0
        // POST: api/User
        public HttpResponseMessage Post([FromBody] User value)
        {
            UserPersistence up = new UserPersistence();
            long            id;

            id       = up.saveUser(value);
            value.ID = id;
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);

            response.Headers.Location = new Uri(Request.RequestUri, String.Format("user/{0}", id));
            return(response);
        }
示例#19
0
        /*
         * Transaction: Delete a book from the database
         * Returns true iff the book exists in the database and
         * it was successfully deleted.
         */
        public static bool DeleteUser(User delUser)
        {
            // Verify that the user already exists
            User oldUser = UserPersistence.GetUser(delUser.UserId);

            // oldUser shouldnot be null, if this is a old user
            if (oldUser == null)
            {
                return(false);
            }
            return(UserPersistence.DeleteUser(delUser));
        }
示例#20
0
        public ActionResult UserName(string name)
        {
            name = (string)Session["UserId"];
            User user = UserPersistence.getUserName(name);

            if (user == null)
            {
                return(HttpNotFound());
            }
            Session["user"] = user;
            return(View("UserName", user));
        }
示例#21
0
        /*
         * Transaction: Update a user in the database
         * Returns true iff the user exists in the database and
         * it was successfully changed.
         */
        public static bool ChangeUser(User upUser)
        {
            // Verify that the user  already exists
            User oldUser = UserPersistence.GetUser(upUser.UserId);

            // oldUser should not be null, if this is a existing user
            if (oldUser == null)
            {
                return(false);
            }
            return(UserPersistence.UpdateUser(upUser));
        }
示例#22
0
        public ActionResult Login(Credential credential)
        {
            if (credential == null)
            {
                return(View(new Credential()));
            }

            if (credential.Password == null || credential.UserId == null)
            {
                string err = "Both User ID and Password are required. Please try again.";
                TempData["message"] = err;
                return(View(credential));
            }

            if (credential.Password.Length == 0 || credential.UserId.Length == 0)
            {
                string err = "Both User ID and Password are required. Please try again.";
                TempData["message"] = err;
                return(View(credential));
            }

            User user = UserPersistence.GetUser(credential.UserId); // Get the user

            if (user.status != "I")                                 // If user is active, Authenticate the user.
            {
                bool result = UserManager.AuthenticateUser(credential, Session);
                if (result) //If username or password is matched with the database value, login the user.
                {
                    TempData["message"] = "";
                    Session["UserId"]   = user.UserId;
                    Session["LoggedIn"] = true;
                    if (user.IsAdmin)
                    {
                        return(RedirectToAction("AdminPage", "Admin"));
                    }
                    else
                    {
                        return(RedirectToAction("ProfilePage", "ProfilePage"));
                    }
                }
                else
                {
                    TempData["message"] = "Invalid login credentials";
                    return(View(credential));
                }
            }
            else // If user is inactive, do not login the user.
            {
                TempData["invalid"] = "Your account has been banned";
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#23
0
        /// <summary>
        /// Makes a new instance of user in the database.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        // POST: api/User
        public HttpResponseMessage Post([FromBody] User value)
        {
            int             id;
            UserPersistence userPersistance = new UserPersistence();

            id = userPersistance.SaveUser(value);

            HttpResponseMessage response = new HttpResponseMessage();

            response = Request.CreateResponse(HttpStatusCode.Created);
            response.Headers.Location = new Uri(Request.RequestUri, String.Format("User/{0}", id));
            return(response);
        }
示例#24
0
        public static User[] GetAllUsers()
        {
            List <User> users = UserPersistence.GetAllUsers();

            if (users != null)
            {
                return(UserPersistence.GetAllUsers().ToArray());
            }
            else
            {
                return(new User[0]);
            }
        }
示例#25
0
        //GET: api/User/5
        public User Get(int id)
        {
            UserPersistence u    = new UserPersistence();
            User            User = u.GetUser(id);

            if (User == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }


            return(User);
        }
示例#26
0
        public ActionResult ResetPassword(string UserId)
        {
            string password = UserPersistence.ResetPassword(UserId.Replace("'", "&apos;"));

            if (password != null)
            {
                ViewBag.message = UserId + "'s password has changed. New password is: " + password;
            }
            else
            {
                ViewBag.message = "There was a problem with transaction. Please try again.";
            }
            return(View("ResetUserPassword", UserPersistence.GetAllUsers()));
        }
示例#27
0
        public User Get(int id)
        {
            UserPersistence userPersistance = new UserPersistence();
            User            user            = userPersistance.GetUser(id);

            if (user.Id != 0)
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
示例#28
0
        public ActionResult ChangeStatus(string Status, string UserId)
        {
            bool result = UserPersistence.ChangeUserStatus(UserId.Replace("'", "&apos;"), Status.Replace("'", "&apos;"));

            if (result)
            {
                ViewBag.message = "Transaction Completed.";
            }
            else
            {
                ViewBag.message = "Transaction Failed. Try Again.";
            }
            return(View("ChangeUserStatus", UserPersistence.GetAllUsers()));
        }
示例#29
0
        /// <summary>
        /// Cria um novo User
        /// </summary>
        /// <param name="Name">Nome do usuario</param>
        /// <param name="Email">Email do usuario</param>
        /// <returns>True se a operacao deu certo, False ao contrario</returns>
        public bool Create(string name, string email)
        {
            // Cria um novo usuario
            User user = new User();

            user.Name  = name;
            user.Email = email;

            // Persiste na base de dados o novo usuario
            UserPersistence userPersistence = new UserPersistence();
            bool            result          = userPersistence.Insert(user);

            return(result);
        }
示例#30
0
        public static UserPersistence MapUserEntityToUserPersistence(User user)
        {
            if (user == null)
            {
                return(null);
            }

            UserPersistence retVal = new UserPersistence()
            {
                Id   = user.Id, Username = user.Username, Jmbg = user.Jmbg,
                Name = user.Name, Password = user.Password, Surname = user.Surname
            };

            return(retVal);
        }