// POST api/profile
        public HttpResponseMessage Post(MyProfileModel value)
        {
            try
            {
                using (var ctx = new Entities())
                {
                    /* Get logged user ID. That won't be fetched from the form to avoid XSS atacks. */
                    int userid = Authentication.GetLoggedUser().UserID;
                    UserProfile profile = ctx.UserProfiles.FirstOrDefault(i => i.UserID == userid);

                    /* If there isn't a profile for this user yet, create it. */
                    if (profile == null)
                    {
                        profile = ctx.UserProfiles.Add(new UserProfile() { UserID = userid });
                    }

                    /* Set user profile info. */
                    profile.FullName = value.FullName;
                    profile.BirthDate = value.BirthDate;
                    profile.UserTheme = value.UserTheme;
                    profile.Location = value.Location;
                    profile.Biography = value.Biography;

                    /* Save changes and refresh user's full name in the cookie. */
                    ctx.SaveChanges();
                    Authentication.RefreshCookie();

                    return new HttpResponseMessage(HttpStatusCode.OK);
                }
            }
            catch
            {
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }
        }
        // POST api/register
        public HttpResponseMessage Post(AuthenticationModel value)
        {
            try
            {
                using (var ctx = new Entities())
                {
                    UserAccount ua = ctx.UserAccounts.Where(i => i.Email == value.Email).FirstOrDefault();

                    /* Check if user isn't registered yet. */
                    if (ua == null)
                    {
                        /* Create the new user and salt the password. */
                        ua = new UserAccount() { Email = value.Email, RegisterDate = DateTime.Now };
                        ua.Password = Authentication.MakePassword(ua, value.Password);
                        ctx.UserAccounts.Add(ua);

                        /* Save changes. */
                        if (ctx.SaveChanges() != 0)
                        {
                            Mail.SendRegisterTokenMail(ua);
                            return new HttpResponseMessage(HttpStatusCode.Created);
                        }
                        else
                        {
                            return new HttpResponseMessage(HttpStatusCode.InternalServerError);
                        }
                    }
                    return new HttpResponseMessage(HttpStatusCode.Conflict);
                }
            }
            catch
            {
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }
        }
        public ActionResult Create(BaselineCreateModel model)
        {
            if (model.Descricao == null || model.Descricao.Trim().Length == 0)
            {
                Error("Digite a descrição do baseline!");
            }
            else
            {
                using (var ctx = new Entities())
                {
                    Baseline bl = new Baseline();
                    bl.CellID = RouteData.Values["cell"].GetCellID();
                    bl.UserID = Authentication.GetLoggedUser().UserID;
                    bl.SetDate = DateTime.Parse(model.SetDate);
                    bl.Message = model.Descricao;
                    ctx.Baselines.Add(bl);

                    if (ctx.SaveChanges() != 0)
                    {
                        Success("Baseline registrado com sucesso!");
                        return RedirectToAction("Index");
                    }
                    else
                    {
                        Error("Erro ao tentar registrar o baseline!");
                    }
                }
            }
            return View(model);
        }
        // DELETE api/teammanage/5
        public HttpResponseMessage Delete(TeamMemberModel value)
        {
            using (var ctx = new Entities())
            {
                Team t = ctx.Teams.FirstOrDefault(i => i.CellID == value.CellId && i.UserID == value.UserId);

                if (t != null)
                {
                    ctx.Teams.Remove(t);

                    if (ctx.SaveChanges() != 0)
                    {
                        return new HttpResponseMessage(HttpStatusCode.OK);
                    }
                    else
                    {
                        return new HttpResponseMessage(HttpStatusCode.InternalServerError);
                    }
                }
                else
                {
                    return new HttpResponseMessage(HttpStatusCode.NotFound);
                }
            }
        }
 // POST api/login
 public HttpResponseMessage Post(RequirementNameModel model)
 {
     try
     {
         using (var ctx = new Entities())
         {
             ctx.ArchiveRequirement(model.CellID, model.Tag);
             ctx.SaveChanges();
             return new HttpResponseMessage(HttpStatusCode.OK);
         }
     }
     catch
     {
         return new HttpResponseMessage(HttpStatusCode.InternalServerError);
     }
 }
 // POST api/profile
 public HttpResponseMessage Post(UseExistingRequirementModel value)
 {
     try
     {
         using (var ctx = new Entities())
         {
             int userID = Authentication.GetLoggedUser().UserID;
             ctx.SelectRequirement(value.Cell, value.LeftTag, value.RightTag, userID, "Alteração de requisito para atender uma nova história");
             ctx.SaveChanges();
             return new HttpResponseMessage(HttpStatusCode.OK);
         }
     }
     catch
     {
         return new HttpResponseMessage(HttpStatusCode.InternalServerError);
     }
 }
        // POST api/teammanage
        public HttpResponseMessage Post(TeamMemberModel value)
        {
            using (var ctx = new Entities())
            {
                Team t = ctx.Teams.FirstOrDefault(i => i.CellID == value.CellId && i.UserID == value.UserId);
                bool createdNew = false;

                if (t != null)
                {
                    t.RoleID = value.RoleId;
                }
                else
                {
                    t = new Team()
                    {
                        CellID = value.CellId,
                        UserID = value.UserId,
                        RoleID = value.RoleId
                    };
                    ctx.Teams.Add(t);
                    createdNew = true;
                }

                if (ctx.SaveChanges() != 0)
                {
                    if(createdNew)
                    {
                        return new HttpResponseMessage(HttpStatusCode.Created);
                    }
                    else
                    {
                        return new HttpResponseMessage(HttpStatusCode.OK);
                    }
                }
                else
                {
                    return new HttpResponseMessage(HttpStatusCode.InternalServerError);
                }
            }
        }
Esempio n. 8
0
        public ActionResult Publish(string tag)
        {
            using (var ctx = new Entities())
            {
                StoriesDetailsModel model = new StoriesDetailsModel(ctx.GetRequirementDetails(tag, null).FirstOrDefault());
                int cellID = RouteData.Values["cell"].GetCellID();

                int userID = Authentication.GetLoggedUser().UserID;
                int ret = ctx.SaveRequirement(RequirementTypes.Publish, cellID, model.RevisionId, userID, "Publicação de história", tag, model.Summary, model.Text, null);

                if (ret != 0)
                {
                    model = new StoriesDetailsModel(ctx.GetRequirementDetails(tag, null).FirstOrDefault());
                    RequirementRevision rev = ctx.RequirementRevisions.FirstOrDefault(i => i.RevisionID == model.RevisionId);
                    rev.Published = true;

                    if (ctx.SaveChanges() != 0)
                    {
                        Success("História publicada com sucesso!");
                        return RedirectToAction("Details", new { @tag = tag });
                    }
                }

                Error("Erro ao tentar publicar a história!");
                return RedirectToAction("Details", new { @tag = tag });
            }
        }
        public ActionResult MarkAsDone(string tag)
        {
            using (var ctx = new Entities())
            {
                RequirementsDetailsModel model = new RequirementsDetailsModel(ctx.GetRequirementDetails(tag, null).FirstOrDefault());
                int cellID = RouteData.Values["cell"].GetCellID();

                int userID = Authentication.GetLoggedUser().UserID;
                int ret = ctx.SaveRequirement(RequirementTypes.MarkAsDone, cellID, model.RevisionId, userID, "Requisito implementado", tag, model.Summary, model.Text, null);

                if (ret != 0)
                {
                    model = new RequirementsDetailsModel(ctx.GetRequirementDetails(tag, null).FirstOrDefault());
                    RequirementRevision rev = ctx.RequirementRevisions.FirstOrDefault(i => i.RevisionID == model.RevisionId);
                    rev.Published = true;

                    if (ctx.SaveChanges() != 0)
                    {
                        Success("Requisito finalizado com sucesso!");
                        return RedirectToAction("Details", new { @tag = tag });
                    }
                }

                Error("Erro ao tentar finalizar o requisito!");
                return RedirectToAction("Details", new { @tag = tag });
            }
        }
Esempio n. 10
0
        public static bool ValidateToken(string token)
        {
            Regex r = new Regex("^UserId:(?<UserId>[0-9]+),Email:(?<Email>.*),Action:(?<Action>[A-Z]+),Expires:(?<Year>[0-9]{4})(?<Month>[0-9]{2})(?<Day>[0-9]{2})(?<Hour>[0-9]{2})(?<Minute>[0-9]{2})(?<Second>[0-9]{2})$");

            byte[] buf = new byte[token.Length / 2];
            for (int i = 0; i < buf.Length; i++)
            {
                buf[i] = byte.Parse(token.Substring(i * 2, 2), NumberStyles.AllowHexSpecifier, null);
            }
            token = Encoding.UTF8.GetString(buf);

            string data = Crypt.DecryptString(token);
            Match m = r.Match(data);

            if (m.Success)
            {
                int uid, day, mon, year, hour, min, sec;
                uid = int.Parse(m.Groups["UserId"].Value);
                day = int.Parse(m.Groups["Day"].Value);
                mon = int.Parse(m.Groups["Month"].Value);
                year = int.Parse(m.Groups["Year"].Value);
                hour = int.Parse(m.Groups["Hour"].Value);
                min = int.Parse(m.Groups["Minute"].Value);
                sec = int.Parse(m.Groups["Second"].Value);

                DateTime expires = new DateTime(year, mon, day, hour, min, sec);

                if (DateTime.UtcNow < expires)
                {
                    using (var ctx = new Entities())
                    {
                        string email = m.Groups["Email"].Value;
                        UserAccount user = ctx.UserAccounts.FirstOrDefault(i => i.UserID == uid && i.Email == email);

                        if (user != null)
                        {
                            switch (m.Groups["Action"].Value)
                            {
                                case "REGISTER":
                                    user.Enabled = true;
                                    if (ctx.SaveChanges() != 0)
                                    {
                                        return true;
                                    }
                                    break;
                            }
                        }
                    }
                }
            }

            return false;
        }