示例#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;
            }
        }