예제 #1
0
파일: Data.cs 프로젝트: rrrhys/Timeclock
 /// <summary>
 /// 
 /// </summary>
 /// <param name="email"></param>
 /// <param name="password"></param>
 /// <returns>A token useful for updating this users data</returns>
 public Guid? CreateUser(string email, string password)
 {
     using (var context = new CWTimeclockEntities())
     {
         var u = new user();
         u.email = email;
         u.name = email.Substring(0, email.IndexOf("@"));
         u.token = Guid.NewGuid();
         u.id = Guid.NewGuid();
         u.password = BCrypt.Net.BCrypt.HashPassword(password);
         context.users.Add(u);
         context.SaveChanges();
         return u.token;
     }
 }
예제 #2
0
        // POST api/tokens
        public HttpResponseMessage Post(user user)
        {
            // we have been given user email and password.
            // if a user matches, send back the guid.

            using (var db = new CWTimeclockEntities())
            {
                var u = db.users.FirstOrDefault(f => f.email.ToLower() == user.email.ToLower());
                if (u != null)
                {
                    if (DataLayer.Utilities.VerifyPasswordMatchesUser(user.password, u))
                    {
                        return Request.CreateResponse(HttpStatusCode.OK, u.token);
                    }
                }

                return Request.CreateResponse(HttpStatusCode.NotFound, "Could not find user.");
            }
        }
예제 #3
0
 private async Task<Guid?> _getTokenForUser(string email, string password)
 {
     using (var client = GetHttpClient())
     {
         user User = new user { email = email, password = password };
         HttpResponseMessage response = client.PostAsJsonAsync(TokenEndpoint,User).Result;
         if (response.IsSuccessStatusCode)
         {
             return await response.Content.ReadAsAsync<Guid>();
         }
         return null;
     }
 }
예제 #4
0
        private async Task<Guid?> _createUser(string email, string password)
        {
            using (var client = GetHttpClient())
            {
                user u = new user();
                u.email = email;
                u.password = BCrypt.Net.BCrypt.HashPassword(password);
                    HttpResponseMessage response = client.PostAsJsonAsync(UserEndpoint, u).Result;
                    
                    if (response.IsSuccessStatusCode)
                    {
                        dynamic content = response.Content.ReadAsAsync<ExpandoObject>().Result;
                        var token = content.token;
                        return new Guid(token);
                    }
                    else
                    {

                    }
                return null;
            }
        }