Exemplo n.º 1
0
 public HttpResponseMessage Login([FromBody] Traveler traveler)
 {
     using (db)
     {
         db.Configuration.ProxyCreationEnabled = false;
         var v = db.Travelers.FirstOrDefault(a => a.email == traveler.email);
         if (v != null)
         {
             if (string.Compare(HashMd5.CreateMD5(traveler.password, v.salt), v.password) == 0 && v.IsEmailVerified == true)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, v));
             }
             else if (string.Compare(HashMd5.CreateMD5(traveler.password, v.salt), v.password) == 0 && v.IsEmailVerified == false)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                    "Email does not active. Please active this email."));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Password doesn't match"));
             }
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Email does not exist"));
         }
     }
 }
Exemplo n.º 2
0
        public HttpResponseMessage Register(Traveler traveler)
        {
            if (ModelState.IsValid)
            {
                var v = isExist(traveler.email);
                if (v)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Email is exist"));
                }

                var s = SaltGenerate.saltStr(10);
                traveler.salt     = s;
                traveler.password = HashMd5.CreateMD5(traveler.password, s);

                traveler.ActivationCode  = Guid.NewGuid();
                traveler.IsEmailVerified = false;
                traveler.Role_id         = 1;
                traveler.createdAt       = DateTime.Now;
                traveler.updatedAt       = DateTime.Now;
                db.Travelers.Add(traveler);
                db.SaveChanges();
                SendVerificationLinkEmail(traveler.email, traveler.ActivationCode.ToString());
                return(Request.CreateResponse(HttpStatusCode.OK, traveler));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }